Hi,
I am unable to get the output from the below script
if ($lun -like 'naa.624a9370*|^c3776b2da*|^427be350a*')
{
$volserial = ($lun.ToUpper()).substring(12)
$pvol = $volumes | where-object { $_.serial -eq $volserial }
Write-Host "###########################################################################################################" -ForegroundColor Green
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $vol.name)
Write-Host "###########################################################################################################" -ForegroundColor Green
}
else
{
write-host
Write-Host "###########################################################################################################" -ForegroundColor Green
write-host 'This datastore is NOT a Storage Volume.'
Write-Host "###########################################################################################################" -ForegroundColor Green
}
If I replace below line
if ($lun -like 'naa.624a9370*|^c3776b2da*|^427be350a*')
with
if ($lun -like 'naa.624a9370*')
I am able to get the output but I want to add additional parameters to search other strings
Please help.
Something like this?
if($lun -match '^naa.624a9370|^C3776B2DAC9A|^427BE350AEF7'){
if($lun -match '^naa.624a9370'){
$volserial = ($lun.ToUpper()).substring(12)
$purevol = $purevolumes | where-object { $_.serial -eq $volserial }
}
else{
$purevol = $purevolumes | where-object { $_.serial -eq $lun }
}
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $purevol.name)
Write-Host "###########################################################################################################" -ForegroundColor Green
}
else {
write-host
Write-Host "###########################################################################################################" -ForegroundColor Green
write-host 'This datastore is NOT a Pure Storage Volume.'
Write-Host "###########################################################################################################" -ForegroundColor Green
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are using the -like parameter with a RegEx expression (used with -match) combined with mask characters (used with -like).
Try with this
if ($lun -match 'naa.624a9370|^c3776b2da|^427be350a')
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Now, one part is working and one part is not working
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $vol.name) >>>>> not getting output, it shows blank
If I use the naa.c2343 id it show the name, if I use the direct serial number, it shows blank
I assume that your looking for canonicalnames that start with any of the three options.
In that case you probably want to do
if ($lun -match '^naa.624a9370|^naa.c3776b2da|^naa.427be350a')
If the 2nd and 3th option only needs to appear anywhere in the canonicalname, you would need to do
if ($lun -match '^naa.624a9370|c3776b2da|427be350a')
The ^ character in a RegEx expression means at the start of the string.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Below are the 3 different types of serial numbers
1st is naa id
2nd and 3rd are serial numbers
Example:
naa.624a9370c3776b2dac9a4f490033ccc5
C3776B2DAC9A4F4900011155
427BE350AEF744380001101B
If anyone of the format is entered, it should show the details
Currently, I am given as below
if ($lun -match '^naa.624a9370*|^c3776b2dac9a*|^427be350aef7*')
{
$volserial = ($lun.ToUpper()).substring(12)
$purevol = $volumes | where-object { $_.serial -eq $volserial }
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $vol.name)
still it is not working....
Try with this RegEx.
It makes the match case-insensitive.
And it escapes the dot.
And also note that I leave out the * at the end of the three patterns.
The following matches all 3 values in my tests.
if ($lun -match '(?i)^naa\.624a9370|(?i)^c3776b2dac9a|(?i)^427be350aef7')
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Still I am not successful, still not working
If I give serial number naa.624a930000076b2dac9a4f4900000000 I get the desired output
But If I provide the direct serial number C3776B2DAC9A4F4900011155 OR 427BE350AEF744380001101B, it shows blank
I have attached the complete script for your reference.
Please assist.
Looks like I can't read that attachment.
But could you do a run of the script and display the content of $lun before the If-statement?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I meant the actual content of $lun, just before the line with the If-statement.
Can you do the following test, it should return 3 x $true.
Which proves that the match works, and that the problem is most probably somewhere else.
$lun = 'naa.624a9370'
$lun -match '(?i)^naa\.624a9370|(?i)^c3776b2dac9a|(?i)^427be350aef7'
$lun = 'c3776b2dac9a'
$lun -match '(?i)^naa\.624a9370|(?i)^c3776b2dac9a|(?i)^427be350aef7'
$lun = '427be350aef7'
$lun -match '(?i)^naa\.624a9370|(?i)^c3776b2dac9a|(?i)^427be350aef7'
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I am getting True in the output
Those lines were to be ran independently, not inside your script.
But ok, since we see 3 x $true, the match is working.
Can no, in your script replace the If-statement with
Write-Output "|$lun|"
if ($lun -match '(?i)^naa\.624a9370|(?i)^c3776b2dac9a|(?i)^427be350aef7')
I just want to see what is in $lun before the If-statement
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Below is the output if I use the serial number, I see blank output in 3 fields
Below is the correct output when I use naa. id. Here I see all the fields are poplulated with correct results
But doesn't that mean that the problem is likely to be in this line?
And not in the If-statement?
$purevol = $purevolumes | where-object { $_.serial -eq $volserial }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks for pointing me to closer to the solution. I had to change from below
$purevol = $purevolumes | where-object { $_.serial -eq $volserial }
To , if I am using the direct serial number as C3776B2DAC9A4F4900011155
$purevol = $purevolumes | where-object { $_.serial -eq $lun }
Now, I have modified my script as
if ($lun -like 'naa.624a9370*')
{
$volserial = ($lun.ToUpper()).substring(12)
$purevol = $purevolumes | where-object { $_.serial -eq $volserial }
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $purevol.name)
Write-Host "###########################################################################################################" -ForegroundColor Green
}
elseif ($lun -like 'C3776B2DAC9A*')
{
$purevol = $purevolumes | where-object { $_.serial -eq $lun }
Write-Host "###########################################################################################################" -ForegroundColor Green
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $purevol.name)
write-host
Write-Host "###########################################################################################################" -ForegroundColor Green
}
elseif ($lun -like '427BE350AEF7*')
{
$purevol = $purevolumes | where-object { $_.serial -eq $lun }
Write-Host "###########################################################################################################" -ForegroundColor Green
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $purevol.name)
write-host
Write-Host "###########################################################################################################" -ForegroundColor Green
}
else
{
write-host
Write-Host "###########################################################################################################" -ForegroundColor Green
write-host 'This datastore is NOT a Pure Storage Volume.'
Write-Host "###########################################################################################################" -ForegroundColor Green
}
Is there a way to short my script by mentioning the above to one line ?
Something like this?
if($lun -match '^naa.624a9370|^C3776B2DAC9A|^427BE350AEF7'){
if($lun -match '^naa.624a9370'){
$volserial = ($lun.ToUpper()).substring(12)
$purevol = $purevolumes | where-object { $_.serial -eq $volserial }
}
else{
$purevol = $purevolumes | where-object { $_.serial -eq $lun }
}
write-host ("The Volume is on FlashArray : " + $EndPoint.EndPoint)
write-host
write-host ("The Volume Name on the FlashArray is : " + $purevol.name)
Write-Host "###########################################################################################################" -ForegroundColor Green
}
else {
write-host
Write-Host "###########################################################################################################" -ForegroundColor Green
write-host 'This datastore is NOT a Pure Storage Volume.'
Write-Host "###########################################################################################################" -ForegroundColor Green
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot LucD, that worked
you are simply superb