Why $MaximumHistoryCount has a Limit

by Oct 8, 2015

If you try and increase your maximum command history, you may run into some limitations:

 
PS C:\> $MaximumHistoryCount  = 100000
The variable cannot be validated because the value 100000 is not a valid value for the Maximum HistoryCount variable.

There is no clue though what the legal ranges are. The interesting part here is just how the variable maintains a validity range. The answer is: the variable has a ValidateRange attribute that you can query:

$variable = Get-Variable MaximumHistoryCount
$variable.Attributes
$variable.Attributes.MinRange
$variable.Attributes.MaxRange 

Whenever you come across a variable that has a numeric limitation that is not implemented through the raw data type, you may want to look at the variable attributes to check whether there is a validator attribute in place.

Twitter This Tip! ReTweet this Tip!