Skip to content

Instantly share code, notes, and snippets.

@smitmartijn
Created May 29, 2025 17:26
Show Gist options
  • Save smitmartijn/944fc2e2a41af5dd7aef6b50afb7b91e to your computer and use it in GitHub Desktop.
Save smitmartijn/944fc2e2a41af5dd7aef6b50afb7b91e to your computer and use it in GitHub Desktop.
# Nuclear restart of SSHD and all connections
$sshConnections = Get-NetTCPConnection -LocalPort 22 -State Established -ErrorAction SilentlyContinue
Stop-Service sshd
foreach ($conn in $sshConnections) {
$process = Get-Process -Id $conn.OwningProcess -ErrorAction SilentlyContinue
if ($process) {
Stop-Process -Id $process.Id -Force
}
}
Start-Service sshd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment