Variables
- Declaration and assignment:
- Scope:
- Local/Script/Global/Private, commonly used for controlling variable visibility between functions and scripts
- Common automatic variables:
$_(current pipeline object),$PSVersionTable,$Args,$Error,$PID,$LastExitCode
- Read environment variables:
$env:Path; Set:$env:MyVar = 'value' - Interpolation and subexpressions:
- String interpolation:
"Hello $name" - Subexpressions:
"2+2=$(int)"
- String interpolation:
Type constraints and type casting:
Tip: Avoid abusing variables in global scope; pass data between functions through parameters and return values to improve maintainability.