What are Automatic Variables? Enlist some commonly used automatic variables?


Posted On: Feb 22, 2018


Automatic variables in the PowerShell are used to store the state information. It is created and maintained by the PowerShell. These are mainly read-only variables.

Some examples of automatic variables are,

  • $$ - it contains the last token received by the session.
  • $/ - it contains the execution status of the last executed operation in the PowerShell.
  • $^ - it contains the first token in the last line.
  • $null – it contains the NULL value.
  • $_ – it contains the current object in the pipeline.
  • $IsWindows – it contains
  • $TRUE if you are running on windows or false.
  • $Error – it contains an array of error objects in the order of the most recent error.
  • $false – it contains the value FALSE.
  • $HOME – it contains the path of the user’s home directory.
  • $PID – it contains the process ID.
  • $IsLinus – it returns true if you are running on Linux or false.
  • $IsMacOS – it returns true if you are running on Mac OS or false.
  • $PSItem – it contains the current value in the pipeline.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    PowerShell Interview Questions

    What is PowerShell?

    PowerShell is a command-line tool built upon the .NET framework to help the windows system administrator. With PowerShell, you can control your system operations such as accessing data storage, regist...

    PowerShell Interview Questions

    How to run a PowerShell script?

    To run a script in the PowerShell, go to the directory where your script is stored on your PowerShell command. Then, run the script by typing the following command. PS C:\script_folder> ./Script.p...

    PowerShell Interview Questions

    How to check powershell version in Windows?

    Open your PowerShell command and type the following command to find the version, PS C:\> $PSVersionTable.PSVersion The major column value of the result is the version of your PowerShell....