Subscribe
Accepted Solution

Invoke-NaSsh : Auth fail

Hi,

How would I write a script that covers typos in authentication?

$SrcFilerName="nas01"

$DstFilerName="nas02"

Add-NaCredential $SrcFilerName

Add-NaCredential $DstFilerName

Invoke-NaSsh -name $SrcFilerName "hostname"

Invoke-NaSsh -name $DstFilerName "hostname"

......

How can I exit the script if a typo is made in either of authentication processes?

If incorrect credentials are supplied the above invoke-nassh cmds errors with:-

Invoke-NaSsh : Auth fail

Thanks, Tim

Re: Invoke-NaSsh : Auth fail

Hi, Tim.  The simplest way is probably to test the credentials using Connect-NaController:

Connect-NaController 10.61.167.60 -Credential root -ErrorAction Stop -Transient

If an error occurs, the script will abort.

If you want more control over the error handling, something like this might work:

$c = Connect-NaController 10.61.167.60 -Credential root -ErrorAction SilentlyContinue -Transient

if ($c -EQ $null) { Write-Host "Connection failed." }