Learning How To Format PowerShell Output With Format-Table

Sometimes I can’t read the PowerShell console well. I’ve always chalked it up to my eyesight and getting old but it turns out after watching this video by Rob, I just wasn’t formatting the output correctly! Now I need to go get a refund from the eye doctor for these new glasses. Thanks, Rob! You’ve saved me money and I also know how to get nice-looking output in the PowerShell console.

I'm going to show you how to use format table to manipulate the output of functions and Commandlets. In this snip. We're going to be working with get service. So I'm going to go ahead and run it and you'll see that a bunch of the output is truncated. You could see that anywhere. You're seeing the 3 dots so let's use format table to fix this. The first thing I'm going to show you is the auto size parameter so will take get service. But this time, we're going to pipe it to format table and we're going to specify the auto size parameter. When we do that, you'll see that values are no longer truncated. It's displaying a mall in full. The next thing we're going to take a look at is the wrap parameter so again taking get service piping it into format table. Instead of auto size. This time, we're going to specify the wrap parameter and you can see like before the values are no longer truncated and any value that was too long to fit in the column size just gets wrapped on to the next line. So far in this snip, we've been working with status name and display name but now we're going to add some additional properties. So to do that, we need to use the property parameter. And let's take the ones we've been working with so will take status name and display name and let's add a new one. Let's add dependent services and you could see when I did that that these are also tab completable, but you can see we now have a new column here dependent services. There might be a time when you want to hide the table headers or property names and just show. The values to do that. There's a parameter called hide table headers. Let's go ahead and run that. And if I scroll to the top here, you can see the table headers are no longer shown. Format table also allows you to do grouping and to do this we're going to use the groupby parameter. When you do group. You have to specify the property. You want to group by so let's go ahead and use status. And when I do this and run it, you'll see that it's now grouped by status. So we have groups of stopped in groups of running status is. The last thing we're going to look at is creating a custom column and taking an action on its values by using what's called a calculated property so I'm going to get service and pipe it into format table and we're going to go back to using the property parameter here and will do status display name. But let's add our own column and we're going to use a calculated property to do this we're going to call it demo column. And we have to give an expression and this is the action. We're going to take are going to take the name of each service in append the word demo on to the end. When I do that just so you can see my column header. We have a new column called demo column and it's taken the name of each service and appended the word demo onto the end of it. That's why I use format table thanks for watching.