Get-VM -Name $FQDN | Invoke-VMScript -GuestCredential $GuestCredential -ScriptType PowerShell -ScriptText { <#Write-Progress -Activity "Windows Update" -Status "Configure Auto Update Settings" Write-Verbose "Configure Windows Updates to never check for updates" $WUSettings = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings $WUSettings.NotificationLevel = 1 $WUSettings.Save() #> Write-Verbose "Search, download and install Windows Updates" #Define update criteria. $Criteria = "IsInstalled=0 and Type='Software'" Write-Verbose "Search for relevant updates" Write-Progress -Activity "Windows Update" -Status "Searching for available and relevant updates" $Searcher = New-Object -ComObject Microsoft.Update.Searcher $SearchResult = $Searcher.Search($Criteria).Updates If ($SearchResult.Count -eq 0) { Write-Verbose "No relevant updates found" } Else { Write-Verbose "Download updates" Write-Progress -Activity "Windows Update" -Status "Downloading updates" $Session = New-Object -ComObject Microsoft.Update.Session $Downloader = $Session.CreateUpdateDownloader() $Downloader.Updates = $SearchResult $Downloader.Download() Write-Verbose "Install updates" Write-Progress -Activity "Windows Update" -Status "Installing updates" $Installer = New-Object -ComObject Microsoft.Update.Installer $Installer.Updates = $SearchResult $Result = $Installer.Install() } }