Microsoft Virtualization Discussions

Invoke-NaSsh : Auth fail

TIM_RUFUS
3,053 Views

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

1 ACCEPTED SOLUTION

cknight
3,053 Views

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." }

View solution in original post

1 REPLY 1

cknight
3,054 Views

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." }

Public