PowerShell - Automatic variables

Automatic variables are just like regular PowerShell variables, except:

  • They are read-only.
  • They are updated by the PowerShell runtime.
  • They contain useful data about the PowerShell environment and the state of your script.

No. Variable Name Description & Example
$$

The last token of the last line executed.

PS C:\> get-date
Saturday, June 3, 2017 10:27:25 PM
PS: C:\> $$
get-date
PS C:\> (get-process).count
152
PS: C:\> $$
count
$?

$^
$_
$args
$consolefilename
$error
$event
$eventargs
$eventsubscriber
$executioncontext
$false
$foreach
$host
$home
$input
$lastexitcode
$matches
$myinvocation
$nestedpromptlevel
$null
$ofs
$pid
$profile
$psboundparameters
$pscmdlet
$pscommandpath
$psculture
$psdebugcontext
$pshome
$psitem
$psscriptroot
$psenderinfo
$psuiculture
$psversiontable
$pwd
Report Error Show Variables
$sender
$shellid
$stacktrace
$this
$true

Ads by Google

Ask a question, send a comment, or report a problem - click here to contact me.

© Richard McGrath