<?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: Ignore Try..Catch on terminating errors in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994818#M113779</link>
    <description>&lt;P&gt;That's what I thought. When I run the code, it actually ALWAYS enters the Catch block as shown here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\Users\jmilano\Documents\PowerShell_Scripts\Datastores&amp;gt; C:\Users\jmilano\Documents\PowerShell_Scripts\TestTryCatch.ps1
Try this....
Try-Catch activated
Finally activated&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the Try..Catch to capture all major terminating errors, however I have one command which i do NOT want to terminate on, I just want the code to continue running. The problem is that the code ALWAYS enters the Catch block and I cannot figger out why I.&lt;/P&gt;&lt;P&gt;Note: Get-Item does not have a location parameter so this should trigger an error which I want to ignore. This is for testing purposes atm.&lt;/P&gt;&lt;P&gt;Even testing from the command line, ErrorAction doesn't work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction Continue
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction Continue
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction Ignore
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction Ignore
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction Inquire
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction Inquire
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction SilentlyContinue
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction SilentlyContinue
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 08 Nov 2023 23:01:11 GMT</pubDate>
    <dc:creator>JDMils_Interact</dc:creator>
    <dc:date>2023-11-08T23:01:11Z</dc:date>
    <item>
      <title>Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994610#M113754</link>
      <description>&lt;P&gt;I'm very sorry for this basic question and I MUST be missing something obvious. I cannot get a terminating error located within a Try..Catch to be ignored and for processing to continue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;$ErrorActionPreference = "Ignore"
Try
    {
    Write-Host "Try this...."
    Get-Item -Location "C:\Temp" -ErrorAction Ignore
    Write-Host "Error ignored"
    }

Catch
    {
    Write-Host "Try-Catch activated"
    }
Finally
    {
    Write-Host "Finally activated"
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I want the terminating error "Get-Item -Location "C:\Temp" -ErrorAction Ignore" to be ignored and processing to continue. In my testing, the Catch block is always processed.&lt;/P&gt;&lt;P&gt;My PS version:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;$PSVersionTable

Name                           Value                                                                                                                                                                                                                            
----                           -----                                                                                                                                                                                                                            
PSVersion                      5.1.14393.6343                                                                                                                                                                                                                   
PSEdition                      Desktop                                                                                                                                                                                                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                                          
BuildVersion                   10.0.14393.6343                                                                                                                                                                                                                  
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                                  
WSManStackVersion              3.0                                                                                                                                                                                                                              
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                                              
SerializationVersion           1.1.0.1             &lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 08 Nov 2023 01:34:03 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994610#M113754</guid>
      <dc:creator>JDMils_Interact</dc:creator>
      <dc:date>2023-11-08T01:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994640#M113756</link>
      <description>&lt;P&gt;With &lt;STRONG&gt;-ErrorAction Ignore&lt;/STRONG&gt; you are in fact disabling the terminating exception.&lt;BR /&gt;So your code will never end in the Catch block.&lt;BR /&gt;&lt;BR /&gt;If the cmdlet(s) you want to capture does/do not have a terminating exception, you must add &lt;STRONG&gt;-ErrorAction Stop.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Nov 2023 07:57:40 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994640#M113756</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-08T07:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994818#M113779</link>
      <description>&lt;P&gt;That's what I thought. When I run the code, it actually ALWAYS enters the Catch block as shown here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\Users\jmilano\Documents\PowerShell_Scripts\Datastores&amp;gt; C:\Users\jmilano\Documents\PowerShell_Scripts\TestTryCatch.ps1
Try this....
Try-Catch activated
Finally activated&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the Try..Catch to capture all major terminating errors, however I have one command which i do NOT want to terminate on, I just want the code to continue running. The problem is that the code ALWAYS enters the Catch block and I cannot figger out why I.&lt;/P&gt;&lt;P&gt;Note: Get-Item does not have a location parameter so this should trigger an error which I want to ignore. This is for testing purposes atm.&lt;/P&gt;&lt;P&gt;Even testing from the command line, ErrorAction doesn't work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction Continue
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction Continue
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction Ignore
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction Ignore
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction Inquire
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction Inquire
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand

PS C:\Users\jmilano\Documents\PowerShell_Scripts&amp;gt; get-item -location "c:\temp" -ErrorAction SilentlyContinue
Get-Item : A parameter cannot be found that matches parameter name 'location'.
At line:1 char:10
+ get-item -location "c:\temp" -ErrorAction SilentlyContinue
+          ~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-Item], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetItemCommand&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 08 Nov 2023 23:01:11 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994818#M113779</guid>
      <dc:creator>JDMils_Interact</dc:creator>
      <dc:date>2023-11-08T23:01:11Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994880#M113783</link>
      <description>&lt;P&gt;The reason the Catch block is activated is because the Get-Item cmdlet does not have a Location parameter.&lt;BR /&gt;I suspect you mean to use the parameter Path there.&lt;BR /&gt;&lt;BR /&gt;Also the Finally block is always executed, independent if there was an error or not.&lt;BR /&gt;&lt;BR /&gt;So my code&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Try { 
    Write-Host "Try this...."
    Get-Item -Path "C:\Temp" -ErrorAction Ignore
    Write-Host "Error ignored"
}
Catch {
    Write-Host "Try-Catch activated"
}
Finally {
    Write-Host "Finally activated"
}
&lt;/LI-CODE&gt;
&lt;P&gt;Correctly shows&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Try this....

    Directory: C:\

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----           14-May-23    13:11                Temp
Error ignored
Finally activated&lt;/LI-CODE&gt;
&lt;P&gt;And if use a non-existing folder, thus provoking an error, I get&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Try this....
Error ignored
Finally activated&lt;/LI-CODE&gt;
&lt;P&gt;No folder was found/listed&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 08:15:31 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2994880#M113783</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-09T08:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995014#M113811</link>
      <description>&lt;P&gt;I was using Get-Item -Location "C:\Temp" because I wanted to create a terminating error, then using the -ErrorAction Ignore, I was hoping the code would ignore the error and continue running.&lt;/P&gt;&lt;P&gt;This is just my way of testing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 22:05:45 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995014#M113811</guid>
      <dc:creator>JDMils_Interact</dc:creator>
      <dc:date>2023-11-09T22:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995020#M113812</link>
      <description>&lt;P&gt;A syntax error is not a terminating exception.&lt;BR /&gt;That error is captured during the syntax check before the PS engine even starts executing the code.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2023 22:53:40 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995020#M113812</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-09T22:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995057#M113814</link>
      <description>&lt;P&gt;encounter the same issue&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2023 07:52:34 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995057#M113814</guid>
      <dc:creator>xuyenphungngoc</dc:creator>
      <dc:date>2023-11-10T07:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore Try..Catch on terminating errors</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995062#M113816</link>
      <description>&lt;P&gt;There is no issue, it works as designed.&lt;BR /&gt;The test is incorrect, see my previous explanation of the difference between syntax checking and runtime exceptions.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Nov 2023 08:01:10 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Ignore-Try-Catch-on-terminating-errors/m-p/2995062#M113816</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-11-10T08:01:10Z</dc:date>
    </item>
  </channel>
</rss>

