Whenever we perform EOW of storage array controller, we are performing datastore migration from OLD datastore to NEW datastore.
After migraion, we are informing Storage team to reclaim those LUNs during that stage, they always double check with us, whether these LUNs can be reclaimed or not. We used to manually check, if these LUNs are detached or not and confirming them.
Always they used to give us LUN ID as below
isrtpxiv32 7811090_01e2 (thp_474) RAID1 1 4388000
isrtpxiv32 7811090_0d8d (thp_630) RAID1 4 4388000
isrtpxiv32 7811090_3b44 (thp_606) RAID1 2 4388000
isrtpxiv32 7811090_3b45 (thp_607) RAID1 3 4388000
Where LUN ID is = 01e2, 0d8d 3b44 3b45 and NAA ID will have these strings ex: NAA.6742b0f0000004530000000000003b45, NAA.6742b0f0000004530000000000003b44.
Now i want to automate this to avoid manual error.
Whenever they give as LUN ID, i would like to check, those string contains LUN(NAA ID) is in place or detached.
Please help me on this.
The V2 switch on the Get-EsxCli cmdlet was introduced already some PowerCLI releases ago.
It allows to work with the newer esxcli objects.
If you are running a PowerCLI version that does not support this, you should seriously consider upgrading.
Try like this
$data = @(
"isrtpxiv32 7811090_01e2 (thp_474) RAID1 1 4388000",
"isrtpxiv32 7811090_0d8d (thp_630) RAID1 4 4388000",
"isrtpxiv32 7811090_3b44 (thp_606) RAID1 2 4388000",
"isrtpxiv32 7811090_3b45 (thp_607) RAID1 3 4388000"
)
$lunIds = $data | %{
($_.Split() | where{$_})[1].Split('_')[1]
}
Foreach($esx in Get-VMHost){
$esxcli = Get-EsxCli -VMHost $esx -V2
Get-ScsiLun -VmHost $esx -LunType disk |
where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.IndexOf('_') + 1)} | %{
$esxcli.storage.core.device.list.Invoke(@{device=$_.CanonicalName}) |
Select @{N='VMHost';E={$esx.Name}},Device,Status,
@{N='Datastore';E={
$canName = $_.Device
$esxcli.storage.vmfs.extent.list.Invoke() |
where{$_.DeviceName -eq $canName} |
Select -ExpandProperty VolumeName}}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
$data = @(
"isrtpxiv32 7811090_01e2 (thp_474) RAID1 1 4388000",
"isrtpxiv32 7811090_0d8d (thp_630) RAID1 4 4388000",
"isrtpxiv32 7811090_0020 (thp_606) RAID1 2 4388000",
"isrtpxiv32 7811090_0024 (thp_607) RAID1 3 4388000"
)
$lunIds = $data | %{
($_.Split() | where{$_})[1].Split('_')[1]
}
Foreach($esx in Get-VMHost){
$esxcli = Get-EsxCli -VMHost $esx -V2
Get-ScsiLun -VmHost $esx -LunType disk |
where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.Length - 4)} | %{
$esxcli.storage.core.device.list.Invoke(@{device=$_.CanonicalName}) |
Select @{N='VMHost';E={$esx.Name}},Device,Status
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
$esxcli = Get-EsxCli -VMHost $esx -V2,
Thank you Lucd,
i will check this and let you know. however
Get-ScsiLun -VmHost $esx -LunType disk |
where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.Length - 4)}
but in certain cases, input might be with 4digit LUN and it also can contain 5 or 6 digit LUN,
during that stage, this is not working properly, what shall we do in that case?
also, if any LUNs status is on, then i need to get its datastore name, how to do?
your scripts are very very high level and i feel like, i am at very very beginning stage 😄
The V2 switch on the Get-EsxCli cmdlet was introduced already some PowerCLI releases ago.
It allows to work with the newer esxcli objects.
If you are running a PowerCLI version that does not support this, you should seriously consider upgrading.
Try like this
$data = @(
"isrtpxiv32 7811090_01e2 (thp_474) RAID1 1 4388000",
"isrtpxiv32 7811090_0d8d (thp_630) RAID1 4 4388000",
"isrtpxiv32 7811090_3b44 (thp_606) RAID1 2 4388000",
"isrtpxiv32 7811090_3b45 (thp_607) RAID1 3 4388000"
)
$lunIds = $data | %{
($_.Split() | where{$_})[1].Split('_')[1]
}
Foreach($esx in Get-VMHost){
$esxcli = Get-EsxCli -VMHost $esx -V2
Get-ScsiLun -VmHost $esx -LunType disk |
where{$lunIds -contains $_.CanonicalName.Substring($_.CanonicalName.IndexOf('_') + 1)} | %{
$esxcli.storage.core.device.list.Invoke(@{device=$_.CanonicalName}) |
Select @{N='VMHost';E={$esx.Name}},Device,Status,
@{N='Datastore';E={
$canName = $_.Device
$esxcli.storage.vmfs.extent.list.Invoke() |
where{$_.DeviceName -eq $canName} |
Select -ExpandProperty VolumeName}}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference