Format-Wide

Exploring PowerShell Cmdlets: Format-Wide

Welcome back to Wahmans PowerShell blog! Today, we’re taking a closer look at the Format-Wide cmdlet. According to Microsoft:

“Formats objects as a wide table that displays only one property of each object.”

This cmdlet is particularly handy when you want to quickly visualize a list of items using only one of their properties, laid out horizontally for readability. Let’s dive into how you can use this versatile tool with a set of examples ranging from beginner-friendly to advanced.

Example 1: Displaying a List of Services

For beginners, a great way to start using Format-Wide is by listing Windows services and displaying only their names.

Get-Service | Format-Wide -Property Name

This will output all service names in a wide format, filling the terminal window horizontally based on its width.

Example 2: Using the -Column Parameter

If you want to control exactly how many columns are displayed, you can use the -Column parameter.

Get-Process | Format-Wide -Property ProcessName -Column 3

This will list the names of running processes formatted into exactly 3 columns, regardless of window width.

Example 3: Formatting a Custom List

Let’s say you have a custom list of strings or numbers—here’s how to format those with Format-Wide:

1..20 | ForEach-Object {"Item$_"} | Format-Wide -Column 4

This will display 20 items named “Item1” to “Item20” organized into 4 columns.

Example 4: Format-Wide with Custom Object Property

For a more advanced example, you might use Format-Wide when working with custom objects. Suppose you’re querying Azure resources or any API and want to just get a wide look at certain properties:

$users = @(
    [PSCustomObject]@{Name="Alice"; Role="Admin"},
    [PSCustomObject]@{Name="Bob"; Role="User"},
    [PSCustomObject]@{Name="Charlie"; Role="Guest"},
    [PSCustomObject]@{Name="Dana"; Role="User"}
)

$users | Format-Wide -Property Name

This will produce a nice column-based layout of just the names of the users, making it easy to scan through.

As you can see, Format-Wide is a simple yet powerful cmdlet for improving the readability of object output in the console. It’s perfect for summarizing lists or scoping in on a single property.

Happy scripting, and I will see you in the next post!

Leave a Reply

Your email address will not be published. Required fields are marked *