Thursday 19 March 2015

Powershell truncates text

I'm guessing many PowerShell users have had this problem and found several ways to work around it. Truncating of text.

When quickly getting an overview over a PowerShell object nothing is wrong with truncating properties that contains large amounts of text, but sometimes you actually are looking for that specific property. Those times it is annoying when you get this:

$object | select Policies

{NT AUTHORITY\LOCAL SERVICE, SomeAccount Account1, SomeAccount Account2, Accountname...}

This "script window" shows me trying to fetch one property out of a already stored object. The text within the property I am looking for is not visible. Its behind those three dots...

The solution is changing the $FormatEnumerationLimit variable of PowerShell.

As standard is is set to 4. As you also see from the "script window" is that we have gotten 4 items from the Policies property. But there is for certain more than 4 items here.

Do something as simple as set $FormatEnumerationLimit to 20 or possibly -1 to get more or unlimited items from the property.
$FormatEnumerationLimit = -1
$object | select Policies

{NT AUTHORITY\LOCAL SERVICE, SomeAccount Account1, SomeAccount Account2, Accountname, MissingAccountName1, 0#.w|DomainName\MissingAccountName2}


Check these blogposts for more info on the subject(1. simple explanation 2. more elaborate explanation):
http://exchangeserverpro.com/how-to-prevent-truncation-of-long-output-in-exchange-management-shell/

http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/20/change-a-powershell-preference-variable-to-reveal-hidden-data.aspx