Nice, that is looking good.
Do you have more that one loop or stack on the system you ran my code against? I'm being quite harsh in how I determine how many shelves are on the system.
What I did was to identify shelves based purely on their ID:
$shelves = Get-NaShelf | select-object id -unique
In my case this isn't an issue as there is only a single stack of shelves, so what I end up with is one list which makes a big assumption that two shelves with the same ID are actually the same shelf.
My memory is a little hazy on this, but I think if you were to have two separate stacks or loops, then it would be permissible to have the same shelf ID present on separate stacks/loops. The consequence of this is when I run this:
$disks = Get-NaDisk | ? {$_.shelf -eq $s.ID}
The returned result would be that $disks would contain all disks which shared a common shelf ID. Essentially this would amalgamate the results if you had duplicate shelf IDs, which consequently would bear little resemblance to reality.
As I say, I've only got one stack here so it is difficult to test, but I think the below substitutions would give a more accurate output:
$shelves = Get-NaShelf -Controller $c
$disks = Get-NaDisk | ? {($_.shelf -eq $s.ID) -and ($_.name -like $s.channel+"*")}
For completeness, it looks something like this:
$hosts = @("filer1a","filer1b")
$hosts | % {
Write-host Connecting to Filer: $_
$c = Connect-NaController $_
#Select distinct shelves from controller
$shelves = Get-NaShelf -Controller $c
foreach ($s in $shelves) {
Write-Host "Shelf: " $s.ID " Channel: " $s.channel
$disks = Get-NaDisk | ? {($_.shelf -eq $s.ID) -and ($_.name -like $s.channel+"*")}
#select distinct aggregates from output
$aggregates = (Get-NaDisk | ? {($_.shelf -eq $s.ID) -and ($_.aggregate -ne $null)}) | select-object aggregate -unique
if ($aggregates -ne $null) {
#select volumes from aggregates
foreach ($a in $aggregates) {
$vols = Get-NaVol -aggregate $a.Aggregate
Write-Host " Aggregate: " $a.Aggregate
Write-Host " Volumes: "
foreach ($v in $vols) {
Write-Host " " $v.Name
}
}
Write-Host " Disks: "
foreach ($d in $disks) {
Write-Host " " $d
}
}
}
}