Windows Powershell Automation Variable _powershell

Source: Internet
Author: User
Tags hash

Powershell Automation variables are variables that are automatically loaded once the Powershell is opened.

These variables are generally stored in content including

User information: For example, user's root directory $home
Configuration information: For example, PowerShell console size, color, background, and so on.
Run-time information: For example, a function is called by WHO, a script runs a directory, and so on.

ps> $HOME
C:\Users\test
ps> $currentProcessID = $pid
ps> $currentProcessID
5356
ps> Get-process-id $pid Handles NPM (k) PM (k) (k)  VM (   M)  CPU (s)   Id processname
-------------  -----   ----------  ------   -------------
  390  30604   33100  172   1.11  5356 PowerShell

ps> $PROFILE
C:\Users\test\Documents\WindowsPowerShell\ Microsoft.PowerShell_profile.ps1

Some of the automation variables in PowerShell can only be read and cannot be written. For example: $Pid.
You can view help for automatic_variables through Get-help about_automatic_variables.
TOPIC
About_automatic_variables

Theme
About_automatic_variables

Brief description
A variable that describes the storage of Windows PowerShell state information.
These variables are created and maintained by Windows PowerShell.

Detailed
The following is a list of automatic variables in Windows PowerShell:

$$ contains the last token in the last line received by the session.
$? Contains the execution state of the last operation.

If the last operation succeeds, it contains TRUE, and the failure contains FALSE.

$^ contains the first token in the last line received by the session. $_ contains the current object in the pipe object.

You can use this variable in a command that performs actions on each object or selected object in the pipeline.
$Args contains an array of parameter values that are not declared and/or passed to a function, script, or script block.

You can declare arguments when you create a function by using the PARAM keyword or by adding a comma-delimited list of parameters after the function name. $ConsoleFileName The path that contains the most recently used console file (. psc1) in the session.

This variable is populated when you start Windows PowerShell with the Psconsolefile parameter or when you export the snap-in name to a console file using the Export-console cmdlet.
When using a Export-console cmdlet with no parameters, it automatically updates the console files that were most recently used in the session.

You can use this automatic variable to determine which file to update. The $Error contains an array of error objects that represent the most recent errors.

The most recent error is the first error object in the array ($Error [0]).
The $Event contains a Pseventargs object that represents an event that is being handled.
This variable is only populated within an Action block of an Event registration command (for example, register-objectevent).
The value of this variable is the same object returned by the Get-event cmdlet.

Therefore, you can use the properties of the $Event variable (for example, $Event. timegenerated) in the Action script block.
The $EventSubscriber contains a Pseventsubscriber object that represents the event subscriber for the event being processed. This variable is populated only within the Action block of the Event Registration command.

The value of this variable is the same object returned by the Get-eventsubscriber cmdlet.
The $ExecutionContext contains a Engineintrinsics object that represents the execution context of the Windows PowerShell host.

You can use this variable to find the execution object that is available for the cmdlet. $False contains False. You can use this variable to represent FALSE in commands and scripts.Instead of using the string "false".

If the string is converted to a non-empty string or a non-0 integer, the string can be interpreted as TRUE. $ForEach an enumerator that contains foreach-object loops.
You can use the properties and methods of the enumerator for the value of the $ForEach variable.

This variable exists only when the for loop is running, and the completion of the loop is removed. $Home contains the full path of the user's home directory.

This variable is equivalent to the%homedrive%%homepath% environment variable. The $Host contains an object that represents the current host application for Windows PowerShell.

You can use this variable to represent the current host in a command, or to display or change the properties of a host, such as $Host. Version, $Host. CurrentCulture or $host. Ui.rawui.setbackgroundcolor ("Red"). $Input An enumerator that contains the input passed to the function. $Input variables are case-sensitive and can only be used for functions and script blocks. (script blocks are essentially unnamed functions.) In the function's Process block, the $Input variable contains the object that is currently in the pipe. After the Process block completes, the value of the $Input is NULL.

If the function does not have a Process block, the $Input value can be used for the end block, which contains all the input for the function.

$LastExitCode contains the exit code for the last windows-based program that is running.
$Matches $Matches variables are used with the-match and-not match operators. When a scalar input is submitted to the-match or-notmatch operator, if a match is detected, a Boolean value is returned and the $Matches automatic variable is populated with a hash table that consists of all matching string values.

For more information about the-match operator, see about_comparison_operators. $MyInvocation contains an object that has information about the current command, such as a script, function, or script block. You can use information in this object, such as the script's path and file name ($myinvocation. Mycommand.path) or the name of the function ($myinvocation. mycommand.name), to identify the current command.

This is useful for finding the name of a running script. $NestedPromptLevel contains the current hint level. Value 0 indicates the original mentionShows the level.

This value is incremented as it enters the nesting level and is decremented when the nesting level is exited. For example, when you use the $Host. Enternestedprompt method, a nested command prompt appears in Windows PowerShell.

When you reach a breakpoint in the Windows PowerShell debugger, a nested command prompt also appears in Windows PowerShell. When you enter a nested prompt, Windows PowerShell pauses the current command, saves the execution context, and increments the value of the $NestedPromptLevel variable.

To create more nested command prompts (up to 128 levels) or to return to the original command prompt, complete the command, or type exit. $NestedPromptLevel variables help you track the level of hints.

You can create an alternate Windows PowerShell command prompt that contains this value to make this value always visible. $NULL contains null or null values.
You can use this variable in commands and scripts to represent NULL instead of using the string "NULL."

If the string is converted to a non-empty string or a non-0 integer, the string can be interpreted as TRUE.

$PID contains the process identifier (PID) of the process that hosts the current Windows PowerShell session. $Profile the full path to the Windows PowerShell configuration file that contains the current user and the current host application. You can use this variable in a command to represent a configuration file. For example, you can use this variable in a command to determine whether a profile has been created: Test-path $profile You can also use this variable in a command to create a profile: New-item-type File-path $pshome-force In addition, you can also Use this variable to open a configuration file in Notepad: Notepad $profile $PSBoundParameters A dictionary that contains activity parameters and their current values. This variable is only a value in a scope, such as a script or function, that declares the parameter.

You can use this variable to display or change the current value of a parameter, or you can pass a parameter value to another script or function. For example: function test {param ($a, $b) # Display The parameters in dictionary format. $psboundparameters # call the Test1 fu Nction with $a and $b. Test1 @pThe sboundparameters} $PsCmdlet contains an object that represents the running Cmdlet or Advanced function. You can use the properties and methods of the object in the cmdlet or function code to respond to the conditions used.

For example, the Parametersetname property contains the name of the parameter set being used, and the Shouldprocess method dynamically adds the WhatIf and Confirm parameters to the cmdlet.

For more information about $PSCmdlet automatic variables, see about_functions_advanced. $PsCulture contains the name of the culture that is currently used in the operating system. The culture determines the display format for items such as numbers, currencies, and dates. This is the value of the system's System.Globalization.CultureInfo.CurrentCulture.Name property.

To get the System.Globalization.CultureInfo object for your system, use the Get-culture cmdlet. $PSDebugContext during debugging, this variable contains information about the debugging environment. At other times, this variable contains a NULL value. Therefore, you can use this variable to indicate whether the debugger has control. After filling, this variable contains a Psdebugcontext object with breakpoints and Invocationinfo properties. The Invocationinfo property has several very useful properties, including the Location property.

The Location property indicates the path of the script being debugged. $PsHome the full path (typically%windir%system32windowspowershellv1.0) of the installation directory that contains Windows PowerShell. You can use this variable in the path of a Windows PowerShell file.
For example, the following command searches the conceptual help topic for the word "variable": Select-string-pattern variable-path $pshome *.txt $PSScriptRoot contains the directory from which you want to execute a script module.

With this variable, the script can use the module path to access other resources. $PsUICulture contains the name of the user interface (UI) culture that is currently used in the operating system. The UI culture determines which text strings are used for user interface elements, such as menus and messages. This is the system.glo of the system.Balization. The value of the CultureInfo.CurrentUICulture.Name property.

To get the System.Globalization.CultureInfo object for your system, use the Get-uiculture cmdlet.
$PsVersionTable contains a read-only hash table that displays detailed information about the version of Windows PowerShell that is running in the current session. The table includes the following items: clrversion: Version buildversion of the Common language runtime (CLR): The current version of build number Psversion:windows PowerShell version number wsmanstackversion:w S-management Stack Version number pscompatibleversions: Version compatible with the current version of Windows PowerShell Serializationversion: Serialization method Versions Psremotingproto

The Colversion:windows PowerShell version of the Remote Management protocol $PWD contains a path object that represents the full path of the current directory. $Sender contains the object that generated this event.
This variable is populated only within the Action block of the Event Registration command.

The value of this variable can also be found in the Sender property of the Pseventargs (System.Management.Automation.PSEventArgs) object returned by Get-event.

$ShellID contains the identifier for the current shell. The $SourceArgs contains an object that represents the event arguments for the event being handled. This variable is populated only within the Action block of the Event Registration command.

The value of this variable can also be found in the Sourceargs property of the Pseventargs (System.Management.Automation.PSEventArgs) object returned by Get-event. The $SourceEventArgs contains an object that represents the first event argument derived from the EventArgs of the event being processed.
This variable is populated only within the Action block of the Event Registration command. The value of this variable can also be returned in Get-event Pseventargs (System.Management.Automation.PSEventArgs) object is found in the Sourceargs property.

$This in a script block that defines a script property or Script method, $This variable references the object to be extended. $True contains True.

 You can use this variable in commands and scripts to represent TRUE.

See Also
About_hash_tables
About_preference_va

Riables
About_variables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.