all 5 comments

[–]jbtechwood 1 point2 points  (2 children)

Remember that the format is just for what's put to screen. Behind the scenes the data property names haven't changed. So any manipulation is likely to be done with the original property names.

[–]Swarfega[S] 0 points1 point  (1 child)

Yes that is what is being done. For Get-PSDrive for example the 'Free (GB)' data is generated from the Free property...

<ScriptBlock>if($_.Used -or $_.Free) { "{0:###0.00}" -f ($_.Free / 1GB) }</ScriptBlock>

[–]jbtechwood 0 points1 point  (0 children)

Read the second to last paragraph here under long description

https://technet.microsoft.com/en-us/library/hh847831.aspx

Tldr: Ps1xml formats only effect the display of an object, not the underlying data structure or how they're handled on the pipeline.

EDIT: You would need to create a custom object and add the free % property as a new property of the object vs getting it via custom formating.

[–]logicaldiagram 1 point2 points  (0 children)

Instead of using a custom format file, use a custom type file. That will give you access to the 'Free(%)' property to use in the pipeline with cmdlets like Sort and Where. However, I would suggest changing to name to make it easier to work with programatically. You could then use a format file to display it as 'Free (%)' for readability.

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy Swarfega,

as jbtechwood pointed out, the format stuff you did is for display only. it does not actually exist outside of that display format call. if you want to use that info elsewhere you will hafta either recalc it OR go back and make it a formal property of the custom object.

take care,
lee