Quantcast
Channel: VMware Communities : All Content - VMware PowerCLI
Viewing all articles
Browse latest Browse all 16717

shutdown VMs and patch esxi host

$
0
0

I got a standalone esxi host to patch and need to manually shutdown the VMs, patch the host via update manager, wait for the host to patch, reboot then power on the vms back on

 

 

 

$vms = get-datacenter xxx | get-vm

foreach ($vm in $vms) {

   if($vm.PowerState -eq 'PoweredOn'){

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

   while($vm.PowerState -eq 'PoweredOn'){

  sleep 5

   $vm = Get-VM -Name $vm.Name

   }

   }

   }

 

set-vmhost -VMHost $vmhost -State Maintenance -Confirm:$false

$baseline | Attach-Baseline -entity $vmhost -Confirm:$false

 

Scan-Inventory -Entity $vmhost

 

 

$baseline | Remediate-Inventory -Entity $vmhost -Confirm:$false -ErrorAction SilentlyContinue

 

get-vmhost -name $vmhost | set-vmhost -state Connected -Confirm:$false

 

$vm | start-vm -confirm:$false

 

 

Will this work. I also have a problem where a vm can get stuck in a shutdown state for a long time. I want to stop the VM if it does not shutdown in say 3 mins. How do i do this?


Viewing all articles
Browse latest Browse all 16717

Trending Articles