VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to Sort the Column

Hi,

Please help as I am unable to sort the column output for "LUN ID"

Get-NSVolume | Select @{N="Vol_Name";E={$_.name}},
@{N="Size(GB)";E={[math]::Round($_.size/1024,2)}},
@{N="EUI";E={$_.serial_number}},
@{N="Status";E={$_.vol_state}},
@{N="IG_Name";E={((Get-NSAccessControlRecord -vol_name $_.name).Initiator_group_name) -Join ('|').Replace('|',"`r`n")}},
@{N="LUN_ID";E={((Get-NSAccessControlRecord -vol_name $_.name).lun) -Join ('|').Replace('|',"`r`n")}} | sort "LUN_ID" | ConvertTo-Html -Head $Header -PreContent "<p><h2>Volume - Initiator Groups Info</h2></p>" -PostContent $post | Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd | ForEach-Object -Process { $_ -replace "`n", "<br>" } >> $reportlocation

 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

What exactly is in the calculated property LUN_ID?

The Sort-Object cmdlet will interpret this property as a String, so if you want to sort on numerical values in that string, you will have to convert the parts into Int.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

What exactly is in the calculated property LUN_ID?

The Sort-Object cmdlet will interpret this property as a String, so if you want to sort on numerical values in that string, you will have to convert the parts into Int.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

LUD ID is a numerical number.

you mean like this ?

Sort-Object -Property {[int]$_.''LUN ID"}

 

Tags (1)
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, if the property only contains numbers.
But I'm not sure what the Join and Replace are doing.
Can you show sample content of that property?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked LucD 🙂 Thank you very much.

I am not sure, why Join and Replace was added, i removed and ran the script that didnt make any difference.

Hence I used {[int]$_."LUN_ID"} that worked.

Reply
0 Kudos