Google News
logo
PowerShell - Interview Questions
What are Automatic variables?
There are so many predefined variables in PowerShell, which are known as the automatic variables. These variables mainly store the information about the PowerShell, and created and maintained by the PowerShell. Any user can't change or update the value of these variables.
 
Following are some very popular Automatic Variables are :
 
$ : This variable includes the last token available in the last line that is received by the session.

$? : This variable may include the completion status of the last operation. If the last operation succeeded, its value is TRUE and FALSE if it has failed.

$^ : It may include the first token of the last line obtained by the session.

$Args : Includes a collection of the undeclared parameters or parameter values. These are handed over to a script, script block, or function. When you construct a function, you can display the parameters by making use of the param keyword or by incorporating a comma-separated list of parameters in parentheses just after the function name.

$Error : This variable includes an array of error objects that represent the most recent errors. The current mistake is the first error object in the array ($Error[0]).

$ForEach : This variable includes the enumerator (not the resulting values) of a ForEach loop. You can make use of the properties and processes of enumerators on the value of the $ForEach variable. This variable lives only while the ForEach loop is operating; it gets deleted post the completion of the loop.

$Home : This variable includes the full path of the customer’s home directory. This variable is the counterpart of the %homedrive%%homepath% environment variables, commonly known as C:\Users<UserName>.

$OFS : $OFS is a remarkable variable that saves a string (Series of characters) that you wish to utilize as an output field separator. Employ this variable when you are transforming an array into a string. By default, the value of $OFS is " ", but you can modify the value of $OFS in your session, by just typing $OFS="<value>". If you are anticipating the default value of " " in your module, script, or configuration output, be mindful that the $OFS default value has not been modified anywhere in your code.
Advertisement