📜  PowerShell自动变量

📅  最后修改于: 2021-01-08 02:31:34             🧑  作者: Mango

自动变量

自动变量是存储Windows PowerShell状态的那些变量。这些变量将包含用户和系统的信息,默认变量,运行时变量和PowerShell设置。这些变量可以由Windows PowerShell创建和维护。

以下是PowerShell中自动变量的列表:

Variable name Description
$$ This variable is used to represent the last token in the last line, which is received by the session.
$? This variable is used to represent the execution status of the last operation. If there is no error, it returns a True value otherwise False.
$^ This variable is used to represent the first token in the last line, which is received by the session.
$_ This variable acts as $PSItem. It contains the current object in the pipeline object.
$args This variable contains an array of values for undeclared parameters that are passed to a script, function, or script block.
$ConsoleFileName This variable is used to represent the path of the console file, which was recently used in the session.
$Error This variable is used to contain an array of error objects which represent the most recent errors.
$Event This variable is used to contain an object of PSEventArgs. PSEventArgs is an object used to represent an event that is being processed.
$EventSubscriber This variable is used to contain an object of PSEventSubscriber. This object shows you an event subscriber of an event that is being processed.
$EventArgs This variable is used to contain an object which represents the argument of the first event.
$false This variable is used to represent the False.
$foreach This variable is used to contain the enumerators of a ForEach loop. This variable exists only while the ForEach loop is executing. And it will be deleted after completion of the loop.
$Home This variable is used to represent the full path of the user’s home directory.
$input This variable contains an enumerator that enumerates all the inputs passed to the function. It is only available to script blocks and functions.
$Host This variable contains an object which shows a current host application for the Windows PowerShell.
$IsLinux If the current session is running on the Linux operating system, this variable contains a $True, otherwise $False.
$IsWindows If the current session is running on the Windows operating system, this variable contains a $True, otherwise $False.
$IsMacOS If the current session is running on MacOS operating system, this variable contains a $True, otherwise $False.
$null This variable is used to represent a null or empty value. We can use it to represent an absent or undefined value in script and commands.
$PID This variable displays the PID of the process, which is hosting the session of the current PowerShell.
$PSItem This variable acts as $_. It contains the current object in the pipeline object.
$PSHome This variable represents the full path of the installation directory for the Windows PowerShell.
$PSVersionTable This variable is used to represent the read-only hash table, which displays the details about the version of PowerShell running in the current session.
$PWD This variable is used to contain the path object, which shows you a full path of the current directory.
$ShellId This variable is used to represent the identifier of the current shell.