# Removes the Homelab Manager agent from this Windows machine: deletes its scheduled task, the installed # script, and its credentials file. # # Run in an ELEVATED Windows PowerShell (Run as administrator): # # [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # iex ((New-Object Net.WebClient).DownloadString('https://homelab.example.lan/agent/windows/uninstall.ps1')) # # (With a self-signed certificate, also run # [Net.ServicePointManager]::ServerCertificateValidationCallback = { $true } # first.) # # NOTE: keep this file plain ASCII (it is downloaded as text). $ErrorActionPreference = 'Stop' $script:TaskName = 'Homelab Manager Agent' $script:InstallDir = Join-Path $env:ProgramData 'HomelabManager' function Uninstall-Agent { $identity = [Security.Principal.WindowsIdentity]::GetCurrent() if (-not ([Security.Principal.WindowsPrincipal]$identity).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'This uninstaller must be run as Administrator. Open PowerShell with "Run as administrator" and try again.' } Write-Output 'Removing Homelab Manager agent...' if (Get-ScheduledTask -TaskName $script:TaskName -ErrorAction SilentlyContinue) { Stop-ScheduledTask -TaskName $script:TaskName -ErrorAction SilentlyContinue Unregister-ScheduledTask -TaskName $script:TaskName -Confirm:$false } # Only the files this agent installed - never the folder wholesale, in case something else was put beside them. foreach ($name in 'homelab-manager-agent.ps1', 'agent.json') { $path = Join-Path $script:InstallDir $name if (Test-Path -LiteralPath $path) { [System.IO.File]::Delete($path) } } if ((Test-Path -LiteralPath $script:InstallDir) -and -not (Get-ChildItem -LiteralPath $script:InstallDir -Force)) { [System.IO.Directory]::Delete($script:InstallDir) } Write-Output 'Done. The agent no longer runs or reports from this machine.' Write-Output 'Its entry (and task history) in Homelab Manager is untouched - delete it from the Servers page if you no longer want it tracked.' } Uninstall-Agent