Cyberithub

How to Format PowerShell command output as List

Advertisements

In this article, we will see how to format PowerShell command output as List. If you are using PowerShell then you might be knowing that most of the cmdlets in PowerShell display output in a tabular format. While tabular format is excellent to see but there are certain circumstances when you really need the output in a List format rather than in tabular one. This goal can be easily achieved by using a cmdlet in PowerShell called Format-List. We will see all the uses of Format-List cmdlet in below section with the help of some real world examples. So, Let's begin !!

 

How to Format PowerShell command output as List

How to Format PowerShell command output as List

Also Read: Powershell(v5) – Running scripts is disabled on this system

The use of Format-List cmdlet in PowerShell is much easier than you think. Let's understand this through an example. Let's say you are running a command in PowerShell which displays output in tabular format as you can see below.

PS C:\> Get-Service VacSvc | Select-Object Name, DisplayName, Status

Name   DisplayName                         Status
----   -----------                         ------
VacSvc Volumetric Audio Compositor Service Stopped

Then to format above command, you just need to pipe(|) the output to Format-List cmdlet as shown below. This will display the output in List format.

PS C:\> Get-Service VacSvc | Select-Object Name, DisplayName, Status | Format-List

Name : VacSvc
DisplayName : Volumetric Audio Compositor Service
Status : Stopped

Alternatively, you can also use above PowerShell command like below where you can list out Name, DisplayName and Status properties of service VacSvc using -Property parameter of Format-List cmdlet.

PS C:\> Get-Service VacSvc | Format-List -Property Name, DisplayName, Status

Name : VacSvc
DisplayName : Volumetric Audio Compositor Service
Status : Stopped

If you want to list out all the properties of service VacSvc then you need to use asterisk(*) with -Property parameter as shown below.

PS C:\> Get-Service VacSvc | Format-List -Property *

Name                : VacSvc
RequiredServices    : {RpcSs}
CanPauseAndContinue : False
CanShutdown         : False
CanStop             : False
DisplayName         : Volumetric Audio Compositor Service
DependentServices   : {}
MachineName         : .
ServiceName         : VacSvc
ServicesDependedOn  : {RpcSs}
ServiceHandle       :
Status              : Stopped
ServiceType         : Win32OwnProcess
StartType           : Manual
Site                :
Container           :

You also have the option to use -DisplayError or -ShowError parameter to debug or indicate any error in the cmdlet at the output.

PS C:\> Get-Service VacSvc | Format-List -Property Name, DisplayName,{ $_ / $null } -DisplayError

Name : VacSvc
DisplayName : Volumetric Audio Compositor Service
$_ / $null : #ERR

Similarly, you can also use -ShowError parameter as shown in below PowerShell command. You can check complete usage of Format-List cmdlet on the Microsoft official website.

PS C:\> Get-Service VacSvc | Format-List -Property Name, DisplayName,{ $_ / $null } -ShowError

Name : VacSvc
DisplayName : Volumetric Audio Compositor Service
$_ / $null :

Failed to evaluate expression " $_ / $null ".
+ CategoryInfo : InvalidArgument: (VacSvc:PSObject) [], RuntimeException
+ FullyQualifiedErrorId : mshExpressionError

Hope above article helped you understood how to format PowerShell command output as List. Please let me know your feedback in the comment box.

Leave a Comment