Windows Server 2016 – Using Format-List to modify PowerShell data output

How to Install Windows Server 2019

There is a special parameter that can be used with just about any PowerShell command or cmdlet in order to display different, and usually more, data from that particular command. This parameter is called Format-List, and if you are a fan of finding as much information as possible about the tools you are working with, this is something you will definitely want to become familiar with. PowerShell is often used to monitor many different facets of Windows Server, and getting to know the intricacies of Format-List will certainly help you to sculpt the output information that you are looking for when performing monitoring functions from the PowerShell command line.

We all know that a dir command will display a list of files and folders that are within our current directory; this works in either Command Prompt or in PowerShell. Let’s start learning how to make use of Format-List by using it to modify the output of our dir information.

Getting ready

We will be running these commands from a PowerShell prompt on one of our Windows Server 2016 machines.

How to do it…

Let’s use Format-List to modify our information output on a couple of different PowerShell cmdlets:

  1. Open up PowerShell with administrative rights.
  2. Browse to a location that contains some files. I have a few saved in my documents folder, so I will input cd documents in order to navigate into my documents folder.
  3. Type dir. Then press Enter. You see the normal output of the dir command, a simple list of files, and a little bit of information about each of them:
  1. Now instead of using a simple dir, give this command a try: Dir | Format-List.
  1. That is a lot more data! As you can see, by simply adding a pipe with Format-List following it, we have enhanced the dir command to give us more information about these files:
  1. Using Format-List by itself will adjust the data output to another default format, but one that contains more information. In order to see everything there is to see in the output of a particular command, you can also add a * to the end of the command. Let’s give that a try.
  2. Type this command: Dir | Format-List *.
  3. Now we have yet another different output of information for these files:
  1. Before we lay this one to rest, let’s test Format-List with another cmdlet just to make sure this isn’t something that only works with file information.
  2. Use the Get-Date cmdlet to see the current date and time. Pretty simple, right?
  1. Now try this: Get-Date | Format-List:

How it works…

As we have shown in this recipe, using the Format-List parameter on the end of any command or cmdlet is a good practice to get into because it can help display much more information than would normally be available with the original command, from system timestamps and file information up to very specific information about NIC settings and system components; making Format-List part of your regular arsenal will therefore help to get you a greater quantity of information that you can use to do your job.

Comments are closed.