<?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: How to Capture Authentication Successes and Failures - PowerShell in Microsoft Virtualization Discussions</title>
    <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/116584#M4782</link>
    <description>&lt;P&gt;Shashanka,&lt;/P&gt;&lt;P&gt;Thanks for the reply. That was exactly what I needed and works perfect for what I was trying to achieve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;</description>
    <pubDate>Wed, 02 Mar 2016 19:31:10 GMT</pubDate>
    <dc:creator>JAL</dc:creator>
    <dc:date>2016-03-02T19:31:10Z</dc:date>
    <item>
      <title>How to Capture Authentication Successes and Failures - PowerShell</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/114479#M4653</link>
      <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;I wrote a PS script to create a NetApp LUN based on a Volume snapshot and, it works great.&amp;nbsp; That is, if you authenticate successfully.&lt;/P&gt;&lt;P&gt;Here is the line of code to attach to a filer:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Connect-NaController $Filer -credential (Get-Credential) -HTTPS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I realized during testing is, even if you give credentials to the Windows Popup that appears, the script will continiue to run, even though is does not accomplish anything based on the authentication failure.&amp;nbsp; What I'd like to do, is have a way to capture both successful and unsuccessful authentication attempts and use a Function to either send a message to the user that their attempt failed or, continue to run the script since the logon attempt was good.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-joe&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 22:22:18 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/114479#M4653</guid>
      <dc:creator>JAL</dc:creator>
      <dc:date>2025-06-04T22:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Capture Authentication Successes and Failures - PowerShell</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/114481#M4656</link>
      <description>&lt;P&gt;Hi Joe,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The simplest way is to simply test for success on the connect command...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if (!Connect-NcController ...) {
    Write-Error "Unable to connect to controller!"
    exit
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Aside from that, the two easiest ways are to use a try/catch block or test for the connection...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;try {
    Connect-NcController ....
} catch {
    Throw "Unable to connect to controller!."
}&lt;/PRE&gt;&lt;PRE&gt;Connect-NcController ....

if (!$global:CurrentNcController) {
   Write-Error "No controller connection is present!"
   exit
}&lt;/PRE&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 22:33:24 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/114481#M4656</guid>
      <dc:creator>asulliva</dc:creator>
      <dc:date>2016-01-08T22:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to Capture Authentication Successes and Failures - PowerShell</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/114538#M4663</link>
      <description>&lt;P&gt;Andrew, thanks for the response.&amp;nbsp; I'm hoping to get to this, this week.&amp;nbsp; I'll let you know how it works out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-joe&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2016 20:37:54 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/114538#M4663</guid>
      <dc:creator>JAL</dc:creator>
      <dc:date>2016-01-11T20:37:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to Capture Authentication Successes and Failures - PowerShell</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/116520#M4780</link>
      <description>&lt;P&gt;So, finally was able to get back to this script but, I'm still having issues trying to capture the error and how to deal with it.&amp;nbsp; Yea, I know I'm a rookie at PS.&lt;/P&gt;&lt;P&gt;It seems that since the PS script is making a request to an external source, I can't or, am having a problem capturing that error.&amp;nbsp; So, as in my first post, if I run this line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;Connect-NaController $Filer -credential (Get-Credential) -HTTPS&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;And put in bad or wrong credentials, I get the following error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;EM&gt; Connect-NaController : Incorrect credentials for NaFiler001.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;At C:\Users\UserName\Downloads\PowerShell Stuff\Scripts\Tests\NA_Logon_Test.ps1:18 char:2&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Connect-NaController $Filer -credential (Get-Credential) -HTTPS&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/EM&gt;&lt;BR /&gt;&lt;EM&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; : InvalidResult: nafiler001:NaController) [Connect-NaController], NaAuthException&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : HttpConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I even tried this but, even with this next example, I get the exact error as above in Italic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;try &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Connect-NaController $Filer -credential (Get-Credential) -HTTPS&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;catch&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$ErrorMessage = $_.Exception.Message&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $FailedItem = $_.Exception.ItemName&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Write-Host "Authentication failed due to $ErrorMessage. The error was $FailedItem"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Break&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realize I'm missing something here but, hopefully someone can get me down the correct path.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 21:23:55 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/116520#M4780</guid>
      <dc:creator>JAL</dc:creator>
      <dc:date>2016-03-01T21:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to Capture Authentication Successes and Failures - PowerShell</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/116541#M4781</link>
      <description>&lt;P&gt;Please use an error action to do what you&amp;nbsp;expect to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;try &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Connect-NaController $Filer -credential (Get-Credential) -HTTPS &lt;FONT color="#800080"&gt;-ErrorAction Stop&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;catch&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;. . . . .&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can also use an error variable to catch the error as an alternative :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Connect-NaController $Filer -credential (Get-Credential) -HTTPS &lt;FONT color="#800080"&gt;-ErrorAction SilentlyContinue&amp;nbsp;-ErrorVariable err&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Now use &lt;STRONG&gt;&lt;FONT color="#800080"&gt;$err&lt;/FONT&gt;&lt;/STRONG&gt; &amp;nbsp;to print the error message&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 09:42:28 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/116541#M4781</guid>
      <dc:creator>Shashanka</dc:creator>
      <dc:date>2016-03-02T09:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to Capture Authentication Successes and Failures - PowerShell</title>
      <link>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/116584#M4782</link>
      <description>&lt;P&gt;Shashanka,&lt;/P&gt;&lt;P&gt;Thanks for the reply. That was exactly what I needed and works perfect for what I was trying to achieve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Joe&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2016 19:31:10 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Microsoft-Virtualization-Discussions/How-to-Capture-Authentication-Successes-and-Failures-PowerShell/m-p/116584#M4782</guid>
      <dc:creator>JAL</dc:creator>
      <dc:date>2016-03-02T19:31:10Z</dc:date>
    </item>
  </channel>
</rss>

