PowerShell: Variable

By Xah Lee. Date: .

Double Quoted String

Variable name starts with a dollar sign $

variable name are not case-sensitive.

Create Variable

$x = 3

variable can be output of a command

$x = dir

variable of a array of values

$x = 3, 4, "some"

Clear Variable

to clear, set it to $null or use Clear-Variable

$x = $null
Clear-Variable $x

Delete Variable

Remove-Item -Path Variable:\varName

Variable with Special Character

variable name can contain space or unicode.

use {} to quote them, like this:

${long var name with space}

If you have a question, put $5 at patreon and message me.


xah powershell logo

More Advanced