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 extension. .PARAMETER Extension Optional. The extension to append to the service name. If not provided, the configured ServiceExtension is used. .EXAMPLE Remove-ApprxrService -Extension 'Test' # Removes the service 'ApprxrServiceTest'. #> function Remove-ApprxrService { [CmdletBinding()] param( [string]$Extension ) $serviceName = if ($Extension) { "ApprxrService$Extension" } else { try { $ext = Get-ApprxrConfigurationValue -Key 'ServiceExtension' -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 } } |