openssh-portable/contrib/win32/openssh/uninstall-sshd.ps1
Paul Higinbotham 043a20b808
Update script to account for PS7.3 native command argument parsing changes (#642)
* Update script to account for PS7.3 native command argument parsing changes

* Update version
2022-12-02 14:58:56 -08:00

38 lines
1.1 KiB
PowerShell

if (!([bool]([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")))
{
throw "You must be running as an administrator, please restart as administrator"
}
$scriptpath = $MyInvocation.MyCommand.Path
$scriptdir = Split-Path $scriptpath
$etwman = Join-Path $scriptdir "openssh-events.man"
if (Get-Service sshd -ErrorAction SilentlyContinue)
{
Stop-Service sshd
sc.exe delete sshd 1>$null
Write-Host -ForegroundColor Green "sshd successfully uninstalled"
}
else {
Write-Host -ForegroundColor Yellow "sshd service is not installed"
}
# Unregister etw provider
# PowerShell 7.3+ has new/different native command argument parsing
if ($PSVersiontable.PSVersion -le '7.2.9') {
wevtutil um `"$etwman`"
}
else {
wevtutil um "$etwman"
}
if (Get-Service ssh-agent -ErrorAction SilentlyContinue)
{
Stop-Service ssh-agent
sc.exe delete ssh-agent 1>$null
Write-Host -ForegroundColor Green "ssh-agent successfully uninstalled"
}
else {
Write-Host -ForegroundColor Yellow "ssh-agent service is not installed"
}