Microsoft Virtualization Discussions
Microsoft Virtualization Discussions
So I did this:
Get-NaIgroup | ForEach-Object {$_.Initiators} | Get-NaLunMapByInitiator | sort ascending | FL InitiatorGroup,LunID,Path
I'm expecting
Get-NaIgroup | ForEach-Object {$_.Initiators} | Get-NaLunMapByInitiator | sort ascending | FL LunId,InitiatorGroup,Path
Wondering if I needed LunId first to sort by.
In the grand scheme of things, the desired end result is to query LunId's find the last LunId and subtract one (-1) for a new LUN/LUN mapping.
Is what I want possible? What am I missing? Where have I fallen short?
Thanks!!
Solved! See The Solution
You just have to tell it which property to sort on:
PS C:\> Get-NaIgroup | ForEach-Object {$_.Initiators} | Get-NaLunMapByInitiator | sort -Property LunId | Format-Table LunId,InitiatorGroup,Path -AutoSize
LunId InitiatorGroup Path
----- -------------- ----
0 viaRPC.iqn.1991-05.com.microsoft:x3550rre8.rtprre.testdomain /vol/vol1/lun4
0 viaRPC.iqn.1991-05.com.microsoft:x3550rre7.rtprre.testdomain /vol/vol1/testlun
1 viaRPC.iqn.1991-05.com.microsoft:x3550rre7.rtprre.testdomain /vol/vol1/testlun2
2 viaRPC.iqn.1991-05.com.microsoft:x3550rre8.rtprre.testdomain /vol/vol1/lun3
2 viaRPC.iqn.1991-05.com.microsoft:x3550rre7.rtprre.testdomain /vol/vol1/lun3
Or you could write a simple script to return the next available LUN ID.
You just have to tell it which property to sort on:
PS C:\> Get-NaIgroup | ForEach-Object {$_.Initiators} | Get-NaLunMapByInitiator | sort -Property LunId | Format-Table LunId,InitiatorGroup,Path -AutoSize
LunId InitiatorGroup Path
----- -------------- ----
0 viaRPC.iqn.1991-05.com.microsoft:x3550rre8.rtprre.testdomain /vol/vol1/lun4
0 viaRPC.iqn.1991-05.com.microsoft:x3550rre7.rtprre.testdomain /vol/vol1/testlun
1 viaRPC.iqn.1991-05.com.microsoft:x3550rre7.rtprre.testdomain /vol/vol1/testlun2
2 viaRPC.iqn.1991-05.com.microsoft:x3550rre8.rtprre.testdomain /vol/vol1/lun3
2 viaRPC.iqn.1991-05.com.microsoft:x3550rre7.rtprre.testdomain /vol/vol1/lun3
Or you could write a simple script to return the next available LUN ID.
Oh it's so simple (or obvious). Makes me think it's one of those things I should have known...but still learning.
How much I get next available LUN ID? I know the default behavior when mapping LUNs is to go 0, 1, 2, 3. We've actually started a 255, 254, 253 etc...
So I need last LUD ID -1 I guess...
Thanks again!! Very much appreciated!
-Descending instead of -Ascending.
J
If I use my above script with -descending instead of -ascending, same behavior.
I noticed in your previous code, you had specified "ascending" in the "Sort-Object" flags. An ascending sort is the default, and cannot be specified by flag. To sort in descending order, please make sure that "-descending" flag includes the "-" at the beginning of the word.
Below are 3 PS snippets that offer different sorted output.
#Provides a list of LUNs sorted by LunID in ascending order without respect to the igroup name
Get-NaIgroup | ForEach-Object {$_.Initiators} | Get-NaLunMapByInitiator | Sort-Object -Property LunId | Format-Table LunID,InitiatorGroup,Path -autosize
#Provides a list of LUNs sorted by LunID in descending order without respect to the igroup name
Get-NaIgroup | ForEach-Object {$_.Initiators} | Get-NaLunMapByInitiator | Sort-Object -Property LunId -descending | Format-Table LunID,InitiatorGroup,Path -autosize
#Provides a list of LUNs sorted by LunID in descending order and by igroup name in ascending order
$igroups = Get-NaIgroup | Sort-Object -Property InitiatorGroupName
$table = foreach ($igroup in $igroups) {
$igroup.Initiators | Get-NaLunMapByInitiator | Sort-Object -Property LunId -Descending
}
$table | Format-Table LunID,InitiatorGroup,Path -autosize
Please let me know which of these (if any) resolves the problem.
Bill
Alternatively, if you just want the number that is one less than the lowest LunID in a give igroup, the code would be...
$igroups = Get-NaIgroup | Sort-Object -Property InitiatorGroupName
foreach ($igroup in $igroups) {
$sortedLunMapping = $igroup.Initiators | Get-NaLunMapByInitiator | Sort-Object -Property LunId -Descending
$nextLunId = ($sortedLunMapping[0].LunID) - 1
Write-Host "For $($igroup.InitiatorGroupName), the next LUN ID is $nextLunId"
}
WOW! Thank you for that! Much appreciated! I'll give it a whack and see what happens!
Thanks!
I realized last night that I sorted the LunID in descending order. I think the LunID sort should be in ascending order to get the correct result. Sorry for the error. So, the updated code would be....
$igroups = Get-NaIgroup | Sort-Object -Property InitiatorGroupName
foreach ($igroup in $igroups) {
$sortedLunMapping = $igroup.Initiators | Get-NaLunMapByInitiator | Sort-Object -Property LunId
$nextLunId = ($sortedLunMapping[0].LunID) - 1
Write-Host "For $($igroup.InitiatorGroupName), the next LUN ID is $nextLunId"
}
Good luck. Please let me know whether it works.
It doesn't work...
I keep getting -1.
I'll continue to hack away at it.
Thanks!
$a = Get-NaIgroup | ForEach-Object {$_.Initiators} | Get-NaLunMapByInitiator | sort LunID | Where-Object { $_.LUNID -ne 0 } | Select-Object -ExpandProperty LUNID -First 1$b = ($a - 1)
The above is what I came up with, and does in fact work.