Skip to content

Instantly share code, notes, and snippets.

@sandeep-sr
Created June 3, 2021 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandeep-sr/08440740b44e92ffc05c8cba09ab08a6 to your computer and use it in GitHub Desktop.
Save sandeep-sr/08440740b44e92ffc05c8cba09ab08a6 to your computer and use it in GitHub Desktop.
powercli - Stop or power-off multiple VM’s
Get-Module -ListAvailable *vm*|Import-Module
$cred=Get-Credential
Connect-VIServer vcenter01 -Credential $cred
$deletevmlist=Get-Content C:\temp\stopvms.txt
foreach($vm in $deletevmlist)
{
$vmstate=get-vm $vm
if($vmstate.PowerState -eq "PoweredOn")
{
write-output ("$vm is powered-on hence stopping it")
Stop-VM -VM $vm -Confirm:$false -RunAsync | Out-Null
Start-Sleep 2
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment