begin { $Service = Get-Service -Name iperf3server -ErrorAction SilentlyContinue } process { if ($null -eq $Service) { Write-Host "Service is not installed" } else { try { & "C:\Program Files\nssm\win64\nssm.exe" remove iperf3server confirm } catch { Write-Error "Failed to uninstall service. $_" } } }