<?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 try catch help in Microsoft Virtualization Discussions</title>
    <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/try-catch-help/m-p/56214#M2657</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is my first foray into trying to trap a specific error in powershell with try/catch and I am stuck.&amp;nbsp; I can't seem to figure out what exactly I need to use to trap this error.&amp;nbsp; I have a loop that is checking a collection of filers, this section of the code is looking for un-failed, un-owned disks.&amp;nbsp; Four of our filers have hardware ownership rather than software ownership so this command fails when run against them.&amp;nbsp; I want to trap for this specific error and just simply continue.&amp;nbsp; The code below is as far as I have gotten, I can't even trap the error and get it to write to the console.&amp;nbsp; What am I doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used this command to get the Sytem.InvalidOperationException; $error[0].Exception.psobject.typenames[0]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{Get-NaDiskOwner -Controller $controller | Where-Object {$_.Owner -lt '' -and $_.IsFailed -eq 0}}&lt;/P&gt;&lt;P&gt;&amp;nbsp; catch[System.InvalidOperationException]{"An Error Occurred"}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the error;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Get-NaDiskOwner : SANOWN not enabled.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;At C:\Users\M00627~1.MFA\AppData\Local\Temp\Untitled5.ps1:4 char:16&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;+ Get-NaDiskOwner &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;nbsp; -Controller $controller | Where-Object {$_.Owner -lt '' -and $_.IsFailed -eq 0}}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidOperation: (rchnas02n1:NaController) [Get-NaDiskOwner], ECIFSSHARINGVIOLATION&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ApiException,DataONTAP.PowerShell.SDK.Cmdlets.Disk.GetNaDiskOwner&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Jun 2025 06:36:39 GMT</pubDate>
    <dc:creator>thepunisher</dc:creator>
    <dc:date>2025-06-05T06:36:39Z</dc:date>
    <item>
      <title>try catch help</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/try-catch-help/m-p/56214#M2657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is my first foray into trying to trap a specific error in powershell with try/catch and I am stuck.&amp;nbsp; I can't seem to figure out what exactly I need to use to trap this error.&amp;nbsp; I have a loop that is checking a collection of filers, this section of the code is looking for un-failed, un-owned disks.&amp;nbsp; Four of our filers have hardware ownership rather than software ownership so this command fails when run against them.&amp;nbsp; I want to trap for this specific error and just simply continue.&amp;nbsp; The code below is as far as I have gotten, I can't even trap the error and get it to write to the console.&amp;nbsp; What am I doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used this command to get the Sytem.InvalidOperationException; $error[0].Exception.psobject.typenames[0]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{Get-NaDiskOwner -Controller $controller | Where-Object {$_.Owner -lt '' -and $_.IsFailed -eq 0}}&lt;/P&gt;&lt;P&gt;&amp;nbsp; catch[System.InvalidOperationException]{"An Error Occurred"}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the error;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Get-NaDiskOwner : SANOWN not enabled.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;At C:\Users\M00627~1.MFA\AppData\Local\Temp\Untitled5.ps1:4 char:16&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;+ Get-NaDiskOwner &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;nbsp; -Controller $controller | Where-Object {$_.Owner -lt '' -and $_.IsFailed -eq 0}}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidOperation: (rchnas02n1:NaController) [Get-NaDiskOwner], ECIFSSHARINGVIOLATION&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ApiException,DataONTAP.PowerShell.SDK.Cmdlets.Disk.GetNaDiskOwner&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Jun 2025 06:36:39 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/try-catch-help/m-p/56214#M2657</guid>
      <dc:creator>thepunisher</dc:creator>
      <dc:date>2025-06-05T06:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: try catch help</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/try-catch-help/m-p/56219#M2658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Get-NaDiskOwner -Controller $controller -ErrorAction SilentlyContinue&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Toolkit throws mostly non-terminating errors, so try/catch isn't going to help unless you set the error action to "Stop".&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jan 2012 23:05:29 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/try-catch-help/m-p/56219#M2658</guid>
      <dc:creator>cknight</dc:creator>
      <dc:date>2012-01-25T23:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: try catch help</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/try-catch-help/m-p/56227#M2659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, that explains why I couldn't get try/catch to work.&amp;nbsp; I will most likely use this syntax and then check the variable $err for anything other than the SANOWN error.&amp;nbsp; Thanks Clinton.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Get-NaDiskOwner -Controller $controller -ErrorAction SilentlyContinue -ErrorVariable err | Where-Object {$_.Owner -lt '' -and $_.IsFailed -eq 0}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jan 2012 03:18:41 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/try-catch-help/m-p/56227#M2659</guid>
      <dc:creator>thepunisher</dc:creator>
      <dc:date>2012-01-26T03:18:41Z</dc:date>
    </item>
  </channel>
</rss>

