Powershell - The $FormatEnumerationLimit variable

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!

Hello,

A new article to introduce the $FormatEnumerationLimit variable and when Format-Table -Wrap doesn’t work.

Depending on the size of your console and font size, the content may not be truncated in my demonstration commands. You can in Windows Terminal or Powershell enlarge the font size punctually by pressing CTRL and turning the mouse wheel to get a conclusive result.

# Let's take the following example, where dependentservices is truncated for some services
Get-Service | Format-Table -Property name, dependentservices
# To display the truncated content, we're tempted to do this
Get-service | Format-Table -Property name, dependentservices -wrap
# Syntax that works very well in this context
Get-Process ShellExperienceHost | Format-Table -Property name,path
Get-Process ShellExperienceHost | Format-Table -Property name,path -wrap
# Compare :
Get-Process ShellExperienceHost | Format-Table -Property name,path
Get-Service nsi | Format-Table -Property name, dependentservices
# The difference is in the {}, they indicate a collection of objects (Array).
# To display the full contents of dependentservices, I need to extend the property
Get-Service nsi | Select-Object -ExpandProperty dependentservices
# or
(Get-Service nsi).dependentservices
# You can check the type of dependentservices:
(Get-Service nsi | Select-Object -ExpandProperty dependentservices).gettype()
# But if I want to display the contents of dependentservices for all services, the result is unreadable
Get-Service | Select-Object -ExpandProperty dependentservices
# In this case, you can modify a variable which indicates the number of elements to list (4 by default).
# Display the value of the default variable
$FormatEnumerationLimit
# 4, the maximum number of results displayed in the collection
# Modify the value of $FormatEnumerationLimit
$FormatEnumerationLimit = 8
Get-Service nsi | Format-Table -Property name, dependentservices
# It may be necessary to add a -wrap depending on the number of characters supported by the console and the number of characters to be displayed

Related links