Reply to Message

View discussion in a popup

Replying to:
BenLiebowitz
Expert
Expert

I've found it a lot easier to do this via PowerCLI... 

$vc = vcenter1

$dc = "Datacenter"

Connect-VIServer $vc

# Gets the list of all VMs in the datacenter (except the vCenter VM itself)

$vms = Get-datacenter -Name $dc | Get-VM | where {$_.Name -ne $vc -and $_.PowerState -eq "PoweredOn"}

# Shuts down the VMs in the datacenter that are in a powered on state.

Foreach ($vm in $vms){

  if($vm.ExtensionData.Config.Tools.ToolsVersion -ne "0"){

  #gracefully shutdown

  Shutdown-VMGuest -VM $vm -Confirm:$false

  sleep -Seconds 60

  }

  #forcefully stopping VM

  Stop-VM -VM $vm -Confirm:$false

  }

# Shutdown vCenter VM (Comment out if vCenter is not virtual)

sleep -seconds 120

Shutdown-VMGuest -VM $vc-Confirm:$false

Ben Liebowitz, VCP vExpert 2015, 2016, & 2017 If you found my post helpful, please mark it as helpful or answered to award points.

View solution in original post

Reply
0 Kudos