Application Integration
cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Powershell Try Catch Not Working

 
Highlighted
Occasional Advisor

Powershell Try Catch Not Working

Hi,
I seem to be having an issue using Try/ Catch with the Nimble Powershell Module. I have done a lot of testing but the try never seems to go to catch on a terminating failure.

 

EX:

    try{
        $newvol = New-NSVolume -name "$name" -size $size -perfpolicy 0316a3d10c4302926200000000000000000000001f -folder 2f16a3d10c43029262000000000000000000000001 -multi_initiator 1 
        Write-Host Created Volume $name
    } 
    catch {
        Write-Host failed to create volume $name
}

This will spit out a terminal error and kill the script without running the catch when I feed it a name of a volume that already exists. Am i doing something wrong here? I have used Try Catch before it just doesn't work with the Nimble module.

If anyone else has had this issue and found a workaround that would be helpful.

Edit: Added clarification.

2 REPLIES 2
Highlighted

Re: Powershell Try Catch Not Working

I tried the similar code and seems the "Try-Catch" works for me....

My Powershell Script:

Connect-NSGroup -group 10.206.9.10 -credential admin -IgnoreServerCertificate

$name="Volume-Try-Catch"
$size=10000

try
{
$newvol = New-NSVolume -name "$name" -size $size -perfpolicy 034ebc54516d750de1000000000000000000000014 -multi_initiator 1
Write-Host Created Volume $name

}

catch {
Write-Host failed to create volume $name

}

 

Script Output:

PS C:\Users\Administrator> Get-NSVolume

PS C:\Users\Administrator> Connect-NSGroup -group 10.206.9.10 -credential admin -IgnoreServerCertificate

$name="Volume-Try-Catch"
$size=10000

try
{
$newvol = New-NSVolume -name "$name" -size $size -perfpolicy 034ebc54516d750de1000000000000000000000014 -multi_initiator 1
Write-Host Created Volume $name

}

catch {
Write-Host failed to create volume $name

}

Successfully connected to array 10.206.9.10


Created Volume Volume-Try-Catch

PS C:\Users\Administrator> Get-NSVolume

Name id Size vol_state perfpolicy_name thinly_provisioned block_size description
---- -- ---- --------- --------------- ------------------ ---------- -----------
Volume-Try-Catch 0651de34f45931ae3f000000000000000000000005 10000 online VMware ESX 5 True 4096

 

PS C:\Users\Administrator> Connect-NSGroup -group 10.206.9.10 -credential admin -IgnoreServerCertificate

$name="Volume-Try-Catch"
$size=10000

try
{
$newvol = New-NSVolume -name "$name" -size $size -perfpolicy 034ebc54516d750de1000000000000000000000014 -multi_initiator 1
Write-Host Created Volume $name

}

catch {
Write-Host failed to create volume $name

}

Successfully connected to array 10.206.9.10


failed to create volume Volume-Try-Catch

PS C:\Users\Administrator>

 

 



Thomas Lam - Global Storage Field CTO


I work for HPEAccept or Kudo
Highlighted
HPE Blogger

Re: Powershell Try Catch Not Working

In PowerShell some are stoppable and some are not-stoppable errors. The stoppable errors only raise exception otherwise not. But you can forcefully raise exception on error using '-ErrorAction Stop'.

New-NSVolume -name .... ... etc -ErrorAction Stop'


Regards

Ravi
HPE Nimble Storage