2,187
edits
m (→Array Types: Update ArrayList create example) |
(→Macros / Built-in Variables: Added $env) |
||
Line 460: | Line 460: | ||
== Macros / Built-in Variables == | == Macros / Built-in Variables == | ||
{|class="vwikitable" | {|class="vwikitable" | ||
|- | |- | ||
! Variable !! Description | ! Variable !! Description | ||
|- | |- | ||
| <code> $_ </code> || | | <code> $_ </code> || Variable passed through pipeline from previous command | ||
|- | |- | ||
| <code> $? </code> || Success/failure of previous statement - see [[#Basic_Error_Handler|Basic_Error_Handler]] | | <code> $? </code> || Success/failure of previous statement - see [[#Basic_Error_Handler|Basic_Error_Handler]] | ||
Line 475: | Line 474: | ||
| <code> $foreach </code> || Enumerator in a foreach loop | | <code> $foreach </code> || Enumerator in a foreach loop | ||
|- | |- | ||
| <code> $Host </code> || Information about the machine being executed on | | <code> $Host </code> || Information about the machine being executed on (can also use <code>Get-Host</code> | ||
|- | |- | ||
| <code> $args </code> || Array of arguments passed to a script - see [[#Script_Arguments|Script_Arguments]] | | <code> $args </code> || Array of arguments passed to a script - see [[#Script_Arguments|Script_Arguments]] | ||
|} | |} | ||
=== $env === | |||
This object contains all local system environment variables. For example '''<code>$env:COMPUTERNAME</code>''' provides you with the local system's computer name. | |||
For a full list use... | |||
<source lang="powershell"> | |||
Get-ChildItem env: | |||
</source> | |||
...or for some commonly used ones... | |||
{|class="vwikitable" | |||
|- | |||
! Variable !! Description !! Example data | |||
|- | |||
| APPDATA || Application data path || C:\Users\RodHull\AppData\Roaming | |||
|- | |||
| COMPUTERNAME || Local System's hostname || LAPTOP-01 | |||
|- | |||
| LOGONSERVER || Domain Controller Logged into || DC-SERVER-03 | |||
|- | |||
| PROCESSOR_ARCHITECTURE || CPU Architecture || AMD64 | |||
|- | |||
| USERDOMAIN || Logged in user's domain || DOMAIN.COM | |||
|- | |||
| USERNAME || Local System's hostname || rodhull | |||
|} | |||
[[category:PowerShell]] | [[category:PowerShell]] |