param( [Parameter(Mandatory=$true)] [string]$TargetHost, [int]$ShutdownTimeoutSeconds = 10 ) # 1) Is target computer running? if (-not (Test-Connection -ComputerName $TargetHost -Quiet -Count 1)) { Write-Host "$TargetHost is not accessible; exiting" -ForegroundColor Red exit 1 } # 2) Initiate shutdown Write-Host "Initiating $TargetHost remote shutdown" -ForegroundColor Cyan # Force running apps to close, either /f or /t >0 shutdown /s /m \\$TargetHost /t $ShutdownTimeoutSeconds /f /c "Remote shutdown" # 3) Wait until it stops responding to ping do { Start-Sleep -Seconds 2 } while (Test-Connection -ComputerName $TargetHost -Quiet -Count 1) # Optional extra safety delay Start-Sleep -Seconds 10 # 4) Write-Host "Remote shutdown confirmed; $TargetHost should be ready to cut power." -ForegroundColor Cyan # 5) Now it’s safe to cut power at the PDU / relay # (call your PDU API or GPIO control here)