More Fancy PowerShell Formatting Options
In this issue:
At the end of last year, we explored a variety of custom formatting and display options. I wanted to show you ways you might format PowerShell output to make it easier to consume, or more meaningful. I have a few more options to share with you today. Let's see how much fun we can have.
Format-Fine
First up is a PowerShell module I recently discovered called `FineFormat. You can checkout the project's code repository at https://github.com/sethworks/FineFormat. The module should work on Windows PowerShell and PowerShell 7.
The module contains a single command.
PS C:\> Get-Command -Module FineFormat
CommandType Name Version Source
----------- ---- ------- ------
Function Format-Fine 1.2.0 fineformat
> This is a little confusing because the module name is FineFormat but the command is Format-Fine.
The command has an alias of ff.
The command is designed to make it easier to render or format output based on the type of data. I'm not going to cover every option. You should read full command help and examples. But let me hit a few highlights.
HasValue
I'll start with a simple custom object.
$o = [PSCustomObject]@{
Name = 'Jeff'
Size = 123456
Prop1 = $null
Prop2 = $null
Prop3 = 'Windows 11'
Version = $PSVersionTable.PSVersion
}
PowerShell displays the object as you would expect.
PS C:\> $o
Name : Jeff
Size : 123456
Prop1 :
Prop2 :
Prop3 : Windows 11
Version : 7.5.4
However, using Format-Fine you can easily hide properties that have no value.
PS C:\> $o | Format-Fine -HasValue
Name Size Prop3 Version
---- ---- ----- -------
Jeff 123456 Windows 11 7.5.4
Even though the command is using the Format verb, the output is a custom object. By the way, you could also use the parameter alias of NotNullOrEmpty.
PS C:\> $o | Format-Fine -NotNullOrEmpty | Format-List
Name : Jeff
Size : 123456
Prop3 : Windows 11
Version : 7.5.4
It is just as easily to filter out properties that do have values.
PS C:\> $o | Format-Fine -NoValue
Prop1 Prop2
----- -----
Or search for a value.
PS C:\> $o | Format-Fine -Value "jeff"
Name
----
Jeff
This is especially useful with more complex objects where you'd like to only see defined properties.
PS C:\> Get-CimInstance Win32_ComputerSystem | Format-Fine -HasValue
Caption : PROSPERO
Description : AT/AT COMPATIBLE
Name : PROSPERO
Status : OK
CreationClassName : Win32_ComputerSystem
PrimaryOwnerName : Jeff Hicks
Roles : {LM_Workstation, LM_Server, NT}
PowerState : 0
ResetCapability : 1
AdminPasswordStatus : 0
AutomaticManagedPagefile : True
AutomaticResetBootOption : True
AutomaticResetCapability : True
BootROMSupported : True
BootStatus : {0, 0, 0, 0…}
BootupState : Normal boot
ChassisBootupState : 3
ChassisSKUNumber : Default string
CurrentTimeZone : -300
DaylightInEffect : False
DNSHostName : Prospero
Domain : WORKGROUP
DomainRole : 0
EnableDaylightSavingsTime : True
FrontPanelResetStatus : 2
HypervisorPresent : True
...