Fix Truncated Powershell Output

PowerShell output is truncated for two main reasons: output cannot fit the console window or when PowerShell uses explicit parameters to determine how much output is displayed.

For the first reason, increasing the PowerShell window width may enable you to view more text. However, in other cases, the output may not even fit in the full-screen window.

Examples of Truncated Output

The following command results in truncated output. However, if you increase the Console width, more text is displayed.

In this second example, the first command creates a PowerShell collection (a hash table) and saves it as a variable $hash2

The number of items on a collection that can be displayed on the output console is controlled by the $FormatEnumerationLimit variable. In my case, only four elements in a collection are displayed. We will discuss more of that shortly.

Fixing Truncated PowerShell Output

This Section discusses five possible solutions to truncated output on the PowerShell console.

Solution 1: Fixing truncated output by issuing $FormatEnumerationLimit

If you are dealing with collections, this could be your appropriate solution. If you execute the $FormatEnumerationLimit on PowerShell, you will get the default value for the number of items to display in a collection.

In my case, it is 4.

You can issue a different value with the command.

To get all the values of a collection irrespective of the size, set the value of the variable to 1, that is,

Note: The change you make to $FormatEnumerationLimit applies to the current PowerShell session. As soon as you close the PowerShell, you lose the changes. If you want to save the changes, you can edit the contents of the $profile path. Follow these steps:

  • Get the location of the PowerShell profile by running the following:
  • Check if the PowerShell profile exists already
  • If the output is False, create a profile by running:
  • Open the file on $profile using notepad (you can also edit from the GUI)
  • Add the FormatEnumerationLimit value. Something like
  • Save the file and restart the PowerShell session.

Solution 2: Using Wrap and AutoSize parameters on the Format-Table cmdlet

Format-Table command formats the PowerShell output as a table. To prevent truncation of the output, we can issue -Wrap or -AutoSize parameters on the cmd.

-Wrap option ensures that text that exceeds the column width goes to the next line. By default, PowerShell truncates text that exceeds the column width.

On the other hand, the -AutoSize parameter adjusts the column widths to minimize truncation.

Example: The following command gets the Hash for a file with output formatted.

Solution 3: Formatting output as a list using the Format-List cmdlet

Converting the output into a list can fix the truncation. This is done using the Format-List cmdlet. The command supports wrapping by default.

For example, let’s run the command we executed in Solution 2 and format the output as a list.

Note: You may need to issue to -Force parameter on Format-List to get the desired results.

Solution 4: Selecting the properties we need

Sometimes PowerShell outputs more properties than we need. In such a case, Select-Object can be used to select specified properties of an object.

For example, the following command selects two properties (Status, Name) of Get-Service in the possible three default properties.

Note that you can also use the Format-Table command with -Wrap and -AutoSize parameters for the case above, that is,

Solution 5: Convert the output object into a string, then Limit the width

The output can be piped into the Out-String cmdlet to convert it into a string then the -Width parameter can be issued to control the string width. For example,

The first line creates a hash table with 1 item, and the second command converts the collection into a string and then limits the width to 250 (choosing this because the value is of length 200).

Conclusion

Truncated PowerShell output can be fixed with different methods discussed here. Pay close attention to the kind of output you have on the console and pick the appropriate method.