PoshCode Logo PowerShell Code Repository

Patch-VMHost by afokkema 34 months ago (modification of post by afokkema view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1001"></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.

Arne Fokkema http://ict-freak.nl

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