Automation

 View Only
  • 1.  Unable to Sort the Column

    Posted Feb 15, 2022 07:58 AM

    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

     



  • 2.  RE: Unable to Sort the Column
    Best Answer

    Posted Feb 15, 2022 08:44 AM

    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.



  • 3.  RE: Unable to Sort the Column

    Posted Feb 15, 2022 09:01 AM

    Hi LucD,

    LUD ID is a numerical number.

    you mean like this ?

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

     



  • 4.  RE: Unable to Sort the Column

    Posted Feb 15, 2022 09:10 AM

    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?



  • 5.  RE: Unable to Sort the Column

    Posted Feb 15, 2022 03:52 PM

    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.