Hi all
could someone help, how can sort The -f Format operators.
https://ss64.com/ps/syntax-f-operator.html
for example:
$VMs = Get-Cluster xxxxxx | Get-VM
$Rep = @()
$VMs | foreach {
$Rep += New-Object psobject -Property @{
VM = $_.Name
ProvSpaceGB = &{"{0:n2}" -f ($_.ProvisionedSpaceGB,0)}
}
}
$Rep | sort ProvSpaceGB (it does not work)
Thanks in advance for your help.
Your ProvSpaceGB is a String, not a Float, after the -f operator.
So for example, the value 123 will come before 4.
If you want to sort on the numerical value, you can cast the property on which to sort to a Float.
$Rep | Sort-Object -Property {[float]$_.ProvSpaceGB}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Your ProvSpaceGB is a String, not a Float, after the -f operator.
So for example, the value 123 will come before 4.
If you want to sort on the numerical value, you can cast the property on which to sort to a Float.
$Rep | Sort-Object -Property {[float]$_.ProvSpaceGB}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
Thanks for your answer.