PowerShell: Automatic Variables

By Xah Lee. Date: . Last updated: .

PowerShell has many builtin variables, called automatic variables.

💡 TIP: Variable names are case-insensitive

Environment Related

Home Dir, Init File


home dir env var.


full path of PowerShell: Profile (init file) file. The profile is a init file.

Note that even if this file does not exist, it still returns the path. To check if the file exists, use: test-path $profile.

PowerShell Info


full path of the installation directory for Windows PowerShell.

C:\Program Files\WindowsApps\Microsoft.PowerShell_7.1.4.0_x64__8wekyb3d8bbwe

a object that represents the current host application. Sample value:

Name             : ConsoleHost
Version          : 7.1.4
InstanceId       :
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

A hash table object containing info about your PowerShell version.

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
WSManStackVersion              3.0

Scripting Related

Standard Values


The dotnet True. [see PowerShell: True, False (boolean)]


The dotnet False.

  • Represents the dotnet Null.
  • Variable's default value is $null.
  • $null = command is the most efficient way to suppress output.

Arguments and Script Name


The current object in a pipeline.

dir -recurse | where {$_.length -eq 0}

A Array of the argument received by Function or script or block of code.


value is the object that contains info of your script, function.

# get the script path

# get the script name

# look at what members this object has
$myinvocation | get-member

value is a enumerator object that contains the input that is passed to a function. The items in the enumerator are the objects in the current pipeline.


value is a path object that represents the full path of the current dir.

Iterators; Misc


value is a enumerator object of the current ForEach-Object loop. This var exists only when a “for loop” is running. [see Loop, Iteration]


value is a hash table that represents matched text, from using the -match operator. [see String Operators]



value is True if last operation succeeded, else False.


value is the exit code of the last program.


value is a array of objects, representing the recent errors. $Error[0] is the most recent, $Error[1] is the error before that, etc.

Complete List of Automatic Variables

type help about_automatic_variable