<#
.SYNOPSIS
    Stops + removes the v2 services. Mirrors Install-Services.ps1.

.DESCRIPTION
    Removes the v2 OtOpcUaHost service plus the optional OtOpcUaWonderwareHistorian
    sidecar. Also cleans up legacy service names from prior installs:
    - OtOpcUa (v1 server) — replaced by OtOpcUaHost in v2
    - OtOpcUaAdmin (v1 admin) — fused into OtOpcUaHost in v2
    - OtOpcUaGalaxyHost (pre-7.2 Galaxy host) — long-retired
#>
[CmdletBinding()] param()
$ErrorActionPreference = 'Continue'

foreach ($svc in 'OtOpcUaHost', 'OtOpcUaWonderwareHistorian',
                 'OtOpcUa', 'OtOpcUaAdmin', 'OtOpcUaGalaxyHost') {
    if (Get-Service $svc -ErrorAction SilentlyContinue) {
        Write-Host "Stopping $svc..."
        Stop-Service $svc -Force -ErrorAction SilentlyContinue
        Write-Host "Removing $svc..."
        & sc.exe delete $svc | Out-Null
    } else {
        Write-Host "$svc not installed — skipping"
    }
}
Write-Host "Done."
