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.
- Add-PSSnapin "VMware.VimAutomation.Core"
- Add-PSSnapIn "VMware.VumAutomation"
- # Connect to vCenter
- $VC = Connect-VIServer (Read-Host "Enter vCenter server")
- $vumConfig = Get-VumConfig
- $EsxHost = Get-Inventory -Name (Read-Host "Enter ESX Host")
- $CriticalHost = Get-Baseline -Name "Critical Host Updates"
- $NonCriticalHost = Get-Baseline -Name "Non-critical Host Updates"
- # Enter Maintenance mode
- Set-VMHost $EsxHost -State Maintenance
- # Attach baseline
- Attach-Baseline -Entity $EsxHost -Baseline $CriticalHost, $NonCriticalHost
- # Check Compliance
- $ScanTask = Scan-Inventory $EsxHost -RunAsync
- Wait-Task -Task $ScanTask
- Get-Compliance -Entity $EsxHost
- # Remediate the ESX Host
- $RemediateTask = Remediate-Inventory -Entity $EsxHost -Baseline $CriticalHost, $NonCriticalHost -HostFailureAction $vumConfig.HostFailureAction -Confirm:$false
- Wait-Task -Task $RemediateTask
- # Detach Baseline
- Detach-Baseline -Baseline $CriticalHost, $NonCriticalHost -Entity $EsxHost
- # Exit Mantenance mode
- Set-VMHost $EsxHost -State Connected
- # Disconnect from vCenter
- 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.
PowerShell Code Repository