PowerShell: Variable

By Xah Lee. Date: . Last updated: .

Variable name starts with a dollar sign $

Variable names are case-insensitive.

Variable name can contain space or unicode. Use {} to quote them, like this: ${odd var name}

Create Variable

$x = 3

Variable can store output of a command

$x = dir

Clear Variable

Set it to $null or use Clear-Variable

$x = $null
Clear-Variable $x

Delete Variable

Remove-Item -Path Variable:\varName

 Remove-Item -Path variable:\x

List Variables

Get-ChildItem variable:
PowerShell list variables 2021-09-10
PowerShell list variables

PowerShell

How-to

Advanced

Script Examples