Skip to content

Instantly share code, notes, and snippets.

@AspenForester
Last active June 20, 2018 19:30
Show Gist options
  • Save AspenForester/7ab174e2a9a962383e58a256ff0bb909 to your computer and use it in GitHub Desktop.
Save AspenForester/7ab174e2a9a962383e58a256ff0bb909 to your computer and use it in GitHub Desktop.
Used this to rapidly restart the VMs that got stuck rebooting after being patched. There may be other ways to get the list of machines to consider for restart other than a static list.
$vis = Connect-VIServer MyVcenter
$Servers = @("SomeServers")
foreach ($Server in $servers)
{
if ( -not (Test-NetConnection -ComputerName $Server -CommonTCPPort SMB).TcpTestSucceeded )
# Or maybe some other appropriate test or tests
{
get-vm $Server | Restart-VM -Confirm:$false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment