The other day I shared some ideas on why and how you might want to build a custom format view in PowerShell. As I mentioned in that article, PowerShell ships with a number of custom views for different types of objects.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
Get-Process | Format-Table -view StartTime
How did I know that view existed? What other views exist that I don't know about? This has always been a complicated question to answer. Or more accurately, it is a question with a complicated answer.
In my PowerShell classes, I tell people to use a quick and dirty hack.
Force PowerShell to throw an exception. The error message (mine is in green) tells you the possible view names. You can do this trick with other format commands like Format-List. Be aware that some object types might not have any defined views for Format-List or Format-Table.
I wanted a better way and finally got around to creating it.
In the latest version of the PSScriptTools module, you will find a command called Get-FormatView. This command will display loaded views for the different format controls such as Table or List. If you run the command, the default is to show everything. But you can also specify the type name of an object.
If you pipe Get-Process to Get-Member you'll see the type name. Here's the result using Get-FormatView.
If you see multiple entries for a given format, like Table, the first one should be the default. Often you don't need to do anything. When you run Get-Process alone, the output is automatically formatted with the default view, i.e. process.
Let me load the custom format file I created the other day and re-run the command.
And there's my new view which I can use just as I showed in the earlier article.
Get-Process | Where WS -ge 100MB | Format-Table -view WS
Now you have an easy way to discover new formatting options, and I've given you a tool to easily create your own.
Thanks for your work! Can you provide any tips for setting up PowerShell Terminal? Maybe you already have a video or blog post? Thanks in advance!
You might start with this presentation I did earlier this year. https://www.youtube.com/watch?v=jWpYK2Nd4dg
Great! Thanks again for your blogging. Not many IT professionals find time for this now.