Hello,
I have been trying to figure out what I'm doing wrong here, trying to filter out a naa.6b anything from this script.
All of my other LUN are starting out with naa.600, so I only want the 60 and not 6b, for my output.
Clear
New-VIProperty -Name lunDatastoreName -ObjectType ScsiLun -Value {
param($lun)
$ds = $lun.VMHost.ExtensionData.Datastore | %{Get-View $_} | `
where {$_.Summary.Type -eq "VMFS" -and
($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName -and $_.DiskName -ne "naa.6b*" })}
if($ds){
$ds.Name
}
} -Force | Out-Null
$esxName = "esxi1.lab.local"
Get-VMHost $esxName | Get-ScsiLun | Select lunID, lunDatastoreName, CanonicalName, CapacityMB | Sort lunID
This is the line, I have been working on:
($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName -and $_.DiskName -ne "naa.6b*" })}
Thanks for your help,
-Mike
Actually, I think this is working as expected- it is added the property with the computed value. For those LUNs it is calculating a value of $null. Have you checked this LUN will return the datastore name when you look at it manually?
You could use the -notmatch parameter with a regular expression.
e.g ($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName -and $_.DiskName -notmatch "^naa\.6b.*" })}
Or you could use the -notlike parameter with what you have
e.g ($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName -and $_.DiskName -notlike "naa.6b*" })}
Or you sould use the StartsWith method:
e.g ($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName -and -not $_.DiskName.StartsWith("naa.6b") })}
I'm still getting it, so maybe I have a problem with something else on this line.
I even tried using this and still same result.
($_.Info.Vmfs.Extent | where {$_.DiskName -eq $lun.CanonicalName -and $lun.CanonicalName -notlike "naa.6b*" })}
lunID lunDatastoreName CanonicalName CapacityMB
----- ---------------- ------------- ----------
0 naa.6b8ca3a0f312b2001a2f1be10ae35c71 139366
1 Datastore01 naa.6000d310006d12000000000000000009 2097152
So, all that I want is the naa.6000 and not naa.6b8c.
If this script is using $_.DiskName, to pull out $lun.CanonicalName and I only want to exclude a specific value, then it make sense that I use maybe $lun.CanonicalName and not $_.DiskName
Then the next step would be to filter out, but it is not working.
Thanks,
-Mike
Try using -match instead, $lun.CanonicalName -match "naa.600"
Actually, I think this is working as expected- it is added the property with the computed value. For those LUNs it is calculating a value of $null. Have you checked this LUN will return the datastore name when you look at it manually?
Hi sneddo,
You are spot on, I think we both found it, I need a break too.
It was where I was putting the code.
I finally used, this Get-VMHost $esxName | Get-ScsiLun | Select lunID, lunDatastoreName, CanonicalName, CapacityMB | Sort lunID | Where CanonicalName -Match "naa.600"
Thanks to everyone for the help. glad to get it working.
-Mike