Built-In Variables

PowerShell has several built-in variables that you might find helpful. Some of them you can even modify to alter your PowerShell experience. If you want to make your change permanent, then add the code to your PowerShell profile. Here are few variables you should know:

$PSHOME -- This variable displays the file path where PowerShell is installed:

This is helpful when you want to look at PowerShell's configuration files, perhaps because you want to create custom type extensions:

$MaximumHistoryCount -- This variable has a default value of 64 and it controls the maximum number of history items that PowerShell will retain. Use the Get-History cmdlet to view your history buffer. To change this variable simply assign it a new value:

PS C:\> $MaximumHistoryCount=128

$PID -- If you need to manage the PowerShell process itself, you can use $PID to return the process ID of the current PowerShell process. This may be handy if you have several PowerShell sessions open and want to kill one of them. You need to make sure you kill the right one:

$Profile -- This variable will reference your Windows PowerShell profile script that normally exists in your Documents folder. The variable is automatically populated with this value but you still need to create the script and necessary subdirectory accordingly:

To see these and all the other variables defined in your current PowerShell session, use the Get-Variable cmdlet.

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.