PoshCode Logo PowerShell Code Repository

Patch-VMHost (modification of post by view diff)
View followups from afokkema | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1000"></script>download | new post

This script will patch an ESX Host using VMware Update Manager.

You need to install the VMware.VumAutomation on the host where you want to run this script.

  1. Add-PSSnapin "VMware.VimAutomation.Core"
  2. Add-PSSnapIn "VMware.VumAutomation"
  3.  
  4. # Connect to vCenter
  5. $VC = Connect-VIServer (Read-Host "Enter vCenter server")
  6.  
  7. $vumConfig = Get-VumConfig
  8. $EsxHost = Get-Inventory -Name (Read-Host "Enter ESX Host")
  9. $CriticalHost = Get-Baseline -Name "Critical Host Updates"
  10. $NonCriticalHost = Get-Baseline -Name "Non-critical Host Updates"
  11.  
  12.   # Enter Maintenance mode
  13.   Set-VMHost $EsxHost -State Maintenance
  14.  
  15.   # Attach baseline
  16.   Attach-Baseline -Entity $EsxHost -Baseline $CriticalHost, $NonCriticalHost
  17.                
  18.   # Check Compliance
  19.   $ScanTask = Scan-Inventory $EsxHost -RunAsync
  20.   Wait-Task -Task $ScanTask
  21.  
  22.   Get-Compliance -Entity $EsxHost
  23.  
  24.   # Remediate the ESX Host
  25.   $RemediateTask = Remediate-Inventory -Entity $EsxHost -Baseline $CriticalHost, $NonCriticalHost -HostFailureAction $vumConfig.HostFailureAction -Confirm:$false
  26.                
  27.   Wait-Task -Task $RemediateTask               
  28.                                
  29.   # Detach Baseline
  30.   Detach-Baseline -Baseline $CriticalHost, $NonCriticalHost -Entity $EsxHost
  31.                
  32.   # Exit Mantenance mode
  33.   Set-VMHost $EsxHost -State Connected 
  34.        
  35. # Disconnect from vCenter
  36. Disconnect-VIServer -Confirm:$False

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me