Hi there,
I'm using Invoke-VMScript to have my guest OS install windows updates. That works fine.
After the Invoke-VMScript command is left, I'm calling Restart-VMGuest. Though, this returns "Shutdown VM guest." failed for VM "60TrustedTruste" for the following reason: A general system error occurred: Cannot execute scripts"
I have no idea how to track this issue down. Is there a log on the guest-side, I could check for more details?
Here are snippets of what I'm doing, in case it helps...
Perform windows updates in guest OS:
$script = {
#Define update criteria.
$Criteria = "IsInstalled=0 and Type='Software'";
#Search for relevant updates.
$Searcher = New-Object -ComObject Microsoft.Update.Searcher;
$SearchResult = $Searcher.Search($Criteria).Updates;
#Download updates.
$Session = New-Object -ComObject Microsoft.Update.Session;
$Downloader = $Session.CreateUpdateDownloader();
$Downloader.Updates = $SearchResult;
$Downloader.Download();
#Install updates.
$Installer = New-Object -ComObject Microsoft.Update.Installer;
$Installer.Updates = $SearchResult;
#Result -> 2 = Succeeded, 3 = Succeeded with Errors, 4 = Failed, 5 = Aborted
$Result = $Installer.Install();
return $Result;
}
Wait-Tools -VM $VM -TimeoutSeconds 600
Try {
$result = Invoke-VMScript -VM $VM -ScriptText $script -GuestUser $GuestUser -GuestPassword $GuestPassword -ScriptType Powershell
}
Catch {
Write-Log -EntryType Error -Message "Error invoking guest OS updates." -Exception $_.Exception
}
Restart the guest OS
Wait-Tools -VM $VM -TimeoutSeconds 600 | ||
Restart-VMGuest -VM $VM -Confirm:$false | ||
do { | ||
Start-Sleep -Milliseconds 100 | ||
} until ((Get-VMGuest -VM $VM).State -eq "Running") | ||
Wait-Tools -VM $VM -TimeoutSeconds 600 |
Do you perhaps have custom scripts defined in the Power settings for that VM (see KB1009340).
Can you check if there is anything in the vmware.log ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I don't have any custom scripts, so that was not the issue.
Though, I meanwhile found a stupid logic mistake in my scripts:
I didn't refresh the content of my $VM variable often enough, so it could contain outdated data of a running VM, but it was already off.
Moreover, it seems that using Restart-VMGuest and Get-VMGuest.State or Wait-Tools is not a good combination. The status may be still "Running" even though, the VM began to shut down.
I'm now using Stop-VMGuest and Start-VM explicitly. So far this seems to work better.
Thanks for your thoughts anyway!