<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error handling suggestion in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810465#M98183</link>
    <description>&lt;P&gt;Maybe do a try catch statement.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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'
try{
Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName -GuestCredential $DCLocalCredential
}
catch
{
Write-Host $error[0]
Sleep 10
Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName -GuestCredential $DCLocalCredential
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Nov 2020 04:26:48 GMT</pubDate>
    <dc:creator>Zsoldier</dc:creator>
    <dc:date>2020-11-18T04:26:48Z</dc:date>
    <item>
      <title>Error handling suggestion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810461#M98182</link>
      <description>&lt;P&gt;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 .&amp;nbsp; For example, with my code&lt;/P&gt;&lt;P&gt;My-Logger "Install and configure App Volume Agent..."&lt;BR /&gt;$ConfigureAppVol = 'Write-Verbose -Message "Configuring App Volume Agent" -Verbose;&lt;BR /&gt;$AppVolAgent = "App Volumes Agent.msi";&lt;BR /&gt;$AppVolServer = "AppVol.tataoui.com";&lt;BR /&gt;$AppVolConfig = "/i ""D:\CustomFolder\VMware_AppVol\$AppVolAgent"" /qn REBOOT=ReallySuppress MANAGER_ADDR=$AppVolServer MANAGER_PORT=443";&lt;BR /&gt;Start-Process msiexec.exe -ArgumentList $AppVolConfig -PassThru -Wait'&lt;BR /&gt;Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName -GuestCredential $DCLocalCredential&lt;BR /&gt;&lt;BR /&gt;Once in awhile, instead of getting positive feedback where the code was executed&lt;BR /&gt;ScriptOutput&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------|&lt;BR /&gt;VERBOSE: Configuring App Volume Agent&lt;BR /&gt;|&lt;BR /&gt;| Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName&lt;BR /&gt;| ------- ------ ----- ----- ------ -- -- -----------&lt;BR /&gt;| 15 2 320 788 0.00 1496 0 msiexec&lt;BR /&gt;|&lt;BR /&gt;|&lt;BR /&gt;|&lt;BR /&gt;---------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;I will end up with a very common error like this&amp;nbsp;&lt;BR /&gt;Invoke-VMScript : 11/17/2020 6:37:44 PM Invoke-VMScript The guest operations agent could not be contacted.&lt;BR /&gt;At D:\VMware\New-IsoWindowsUnattendedPlusVMwareTools5-Linux.ps1:419 char:9&lt;BR /&gt;+ Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName - ...&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;+ CategoryInfo : NotSpecified: (:) [Invoke-VMScript], GuestOperationsUnavailable&lt;BR /&gt;+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.ViCore.Cmdlets.Comman&lt;BR /&gt;ds.InvokeVmScript&lt;/P&gt;&lt;P&gt;and that portion of the script will get skip.&amp;nbsp; However, when I get back later and re-run, it will be perfectly fine.&amp;nbsp; To spot the error, I have to scroll back to review the logs and manually rerun each section.&amp;nbsp; 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.&amp;nbsp; Any feedback or suggestion would be appreciated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 03:31:45 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810461#M98182</guid>
      <dc:creator>dwchan</dc:creator>
      <dc:date>2020-11-18T03:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling suggestion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810465#M98183</link>
      <description>&lt;P&gt;Maybe do a try catch statement.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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'
try{
Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName -GuestCredential $DCLocalCredential
}
catch
{
Write-Host $error[0]
Sleep 10
Invoke-VMScript -ScriptText $ConfigureAppVol -VM $strVMName -GuestCredential $DCLocalCredential
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 04:26:48 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810465#M98183</guid>
      <dc:creator>Zsoldier</dc:creator>
      <dc:date>2020-11-18T04:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling suggestion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810473#M98184</link>
      <description>&lt;P&gt;simple enough to add and try.&amp;nbsp; Will add this and do some test run.&amp;nbsp; Stay tune &lt;img class="lia-deferred-image lia-image-emoji" src="https://communities.vmware.com/html/@90D223CDF4C4491D7DFF693BB5C76865/emoticons/1f609.png" alt=":winking_face:" title=":winking_face:" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 05:17:16 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810473#M98184</guid>
      <dc:creator>dwchan</dc:creator>
      <dc:date>2020-11-18T05:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling suggestion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810505#M98186</link>
      <description>&lt;P&gt;Instead of doing a try-catch, you could test in a loop, eventually with a timeout to avoid an endless loop, if the &lt;STRONG&gt;GuestOperationsReady&lt;/STRONG&gt; property in the &lt;A href="https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.vm.GuestInfo.html" target="_blank" rel="noopener"&gt;GuestInfo&lt;/A&gt; object returns $true.&lt;BR /&gt;A simple example, without a timeout.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;while (-not $vm.ExtensionData.Guest.GuestOperationsReady)
    {
      Start-Sleep 2
      $vm.ExtensionData.UpdateViewData('Guest')
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 08:04:01 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810505#M98186</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2020-11-18T08:04:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling suggestion</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810514#M98187</link>
      <description>&lt;P&gt;Oh, and btw, if a cmdlet produces a non-terminating error, it will not jump into the catch block.&lt;BR /&gt;You can force a non-terminating error to become a terminating error by adding the &lt;STRONG&gt;-ErrorAction Stop&lt;/STRONG&gt; parameter.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 08:13:49 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Error-handling-suggestion/m-p/2810514#M98187</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2020-11-18T08:13:49Z</dc:date>
    </item>
  </channel>
</rss>

