Tuesday, November 18, 2014

Powershell: Format-table -Autosize, must remember

I am typing this one out so I remember the -Autosize switch when using Powershell.  Dealing with data in Powershell is practically hopeless without it.  Example:

Sorry the AD tree is so large it can't show the users name, but the black space after the name feild is just offending.

How to fix this?

Powershell is an object based language, and most objects are going to have a lot of data, so when that data gets pushed to a terminal sometimes things don't look so pretty, and in the example above, completely worthless.  Thankfully the Powershell dev's had the same opinion and made the Format-Table command-let in order to help with displaying data on the console.  In this example, just add the Format-Table -Autosize switch to auto width the columns to show the entire string.  For short use ft for Format-Table, and pipe your commandlet to it:
| ft -Autosize

Usable data!