dwchan
Enthusiast
Enthusiast

Error handling suggestion

Want to get feedback from the group as to what are some common/best approach for error handle when invoking a 'invoke-vmscript" command where something the VM may be busy or just doesn't want to run .  For example, with my code

My-Logger "Install and configure App Volume Agent..."
$ConfigureAppVol = 'Write-Verbose -Message "Configuring App Volume Agent" -Verbose;
$AppVolAgent = "App Volumes Agent.msi";
$AppVolServer = "AppVol.tataoui.com";
$AppVolConfig = "/i ""D:\CustomFolder\VMware_AppVol\$AppVolAgent"" /qn REBOOT=ReallySuppress MANAGER_ADDR=$AppVolServer MANAGER_PORT=443";
Start-Process msiexec.exe -ArgumentList $AppVolConfig -PassThru -Wait'
Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName -GuestCredential $DCLocalCredential

Once in awhile, instead of getting positive feedback where the code was executed
ScriptOutput
-----------------------------------------------------------------------------------------------------------------------|
VERBOSE: Configuring App Volume Agent
|
| Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
| ------- ------ ----- ----- ------ -- -- -----------
| 15 2 320 788 0.00 1496 0 msiexec
|
|
|
---------------------------------------------------------------------------------------------------------------------

I will end up with a very common error like this 
Invoke-VMScript : 11/17/2020 6:37:44 PM Invoke-VMScript The guest operations agent could not be contacted.
At D:\VMware\New-IsoWindowsUnattendedPlusVMwareTools5-Linux.ps1:419 char:9
+ Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], GuestOperationsUnavailable
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Comman
ds.InvokeVmScript

and that portion of the script will get skip.  However, when I get back later and re-run, it will be perfectly fine.  To spot the error, I have to scroll back to review the logs and manually rerun each section.  I can either add something like "start-sleep 10" after each install to let everything come to a steady state, or something in powershell / powercli where if an error would occur, it can either decide to wait and try again, or log it to a different log so I can see the overall result much easier.  Any feedback or suggestion would be appreciated 

Reply
0 Kudos