Prof. Powershell

Enum's the Limit

Let's start off 2012 with a tip I learned just recently: Using the PowerShell $FormatEnumerationLimit variable to customize the number of entries viewable via the Dir command.

During the PowerShell Deep Dive conference in Frankfurt last year, PowerShell MVP Thomas Lee, offered up a handy tidbit I thought I should share. I'm sure many of you have run a command like this:

PS C:\> dir hklm:software\microsoft | sort valuecount -desc

   Hive: HKEY_LOCAL_MACHINE\software\microsoft

SKC   VC   Name              Property
---   --   ----              --------
  0   22   NetSh             {4, nshwfp, dhcpclient, wshelper...}
  1   13   FTH               {MaximumMemoryPressurePercentage, Max...
  3   10   InetStp           {SetupString, MajorVersion, IISProgra...
 33    9   Internet Explorer {MkEnabled, Version, Build, W2kVersio...
 17    9   Windows Search    {indexer:ci:MaxRestrictionNodes, Curr...
...

Notice the nested Property value for these entries. The ellipse (...) indicates there are more property values. It might be easier to see them this way:

PS C:\> dir hklm:software\microsoft | sort valuecount -desc | Select -first 4 | format-list

Name        : NetSh
ValueCount  : 22
Property    : {4, nshwfp, dhcpclient, wshelper...}
SubKeyCount : 0

Name        : FTH
ValueCount  : 13
Property    : {MaximumMemoryPressurePercentage,
               MaximumTrackedApplications,
               CheckPointPeriod,
               MaximumDelayFreeOverheadInMBs...}
SubKeyCount : 1

Name        : InetStp
ValueCount  : 10
Property    : {SetupString, MajorVersion, IISProgramGroup,
               VersionString...}
SubKeyCount : 3

Name        : Internet Explorer
ValueCount  : 9
Property    : {MkEnabled, Version, Build, W2kVersion...}
SubKeyCount : 33

Did you also notice that at most all you get is four entries? Turns out there is a built-in PowerShell variable that controls the number of enumerated entries. It has a default value of 4:

PS C:\> $FormatEnumerationLimit
4

But we can modify this variable:

PS C:\> $FormatEnumerationLimit=8

Now watch what happens. I'll use the same Format-List command which makes it easier to see the result:

PS C:\> dir hklm:software\microsoft | sort valuecount -desc | Select -first 4 | format-list

Name        : NetSh
ValueCount  : 22
Property    : {4, nshwfp, dhcpclient, wshelper,
               nshhttp, fwcfg, authfwcfg, 2...}
SubKeyCount : 0

Name        : FTH
ValueCount  : 13
Property    : {MaximumMemoryPressurePercentage,
               MaximumTrackedApplications,
               CheckPointPeriod,
               MaximumDelayFreeOverheadInMBs,
               RuleList, Enabled, TicketValue,
               CrashWindowInMinutes...}
SubKeyCount : 1

Name        : InetStp
ValueCount  : 10
Property    : {SetupString, MajorVersion, IISProgramGroup,
               VersionString, MinorVersion,
               MetabaseSetMajorVersion,
               MetabaseSetMinorVersion, ProductString...}
SubKeyCount : 3

Name        : Internet Explorer
ValueCount  : 9
Property    : {MkEnabled, Version, Build, W2kVersion,
               IntegratedBrowser, svcKBFWLink,
               svcVersion, svcUpdateVersion...}
SubKeyCount : 33

Now PowerShell returned eight nested entries! You can make this variable as large as you think it needs to be. If I set it to a high value, I'm likely to get all the entries:

PS C:\> $FormatEnumerationLimit=64
PS C:\> dir hklm:software\microsoft | sort valuecount -desc | Select –first 1 | format-list

Name        : NetSh
ValueCount  : 22
Property    : {4, nshwfp, dhcpclient, wshelper, nshhttp, fwcfg,
               authfwcfg, 2, netiohlp, whhelper, hnetmon, rpc,
               dot3cfg, napmontr, nshipsec, nettrace, WcnNetsh,
               p2pnetsh, wwancfg, wlancfg, peerdistsh, 7}
SubKeyCount : 0

Of course, as soon as I start a new PowerShell session I'm back to the default value of 4. So if you want a more permanent setting, you'll need to set the value for $FormatEnumerationLimit in your profile.

About the Author

Jeffery Hicks is an IT veteran with over 25 years of experience, much of it spent as an IT infrastructure consultant specializing in Microsoft server technologies with an emphasis in automation and efficiency. He is a multi-year recipient of the Microsoft MVP Award in Windows PowerShell. He works today as an independent author, trainer and consultant. Jeff has written for numerous online sites and print publications, is a contributing editor at Petri.com, and a frequent speaker at technology conferences and user groups.

comments powered by Disqus
Most   Popular

Upcoming Training Events

0 AM
Live! 360 Orlando
November 17-22, 2024
TechMentor @ Microsoft HQ
August 11-15, 2025