Public/ps1/Configuration/Service/Remove-ApprxrService.ps1

<#
.SYNOPSIS
    Removes the Apprxr Windows service.
.DESCRIPTION
    Stops and deletes the Apprxr Windows service using the correct service name, optionally using an NameExtension.
.PARAMETER NameExtension
    Optional. The NameExtension to append to the service name. If not provided, the configured ServiceNameExtension is used.
.EXAMPLE
    Remove-ApprxrService -NameExtension 'Test'
    # Removes the service 'ApprxrServiceTest'.
#>

function Remove-ApprxrService {
    [CmdletBinding()]
    param(
        [string]$NameExtension
    )
    $serviceName = if ($NameExtension) {
        "ApprxrService$NameExtension"
    } else {
        try {
            $ext = Get-ApprxrConfigurationValue -Key 'ServiceNameExtension' -ErrorAction Stop
            if ($ext) { "ApprxrService$ext" } else { "ApprxrService" }
        } catch {
            "ApprxrService"
        }
    }
    if (Get-Service -Name $serviceName -ErrorAction SilentlyContinue) {
        try {
            Stop-Service -Name $serviceName -Force -ErrorAction SilentlyContinue
        } catch {}
        sc.exe delete $serviceName | Out-Null
        Write-Host "Service '$serviceName' removed." -ForegroundColor Green
    } else {
        Write-Host "Service '$serviceName' does not exist." -ForegroundColor Yellow
    }
}