PowerShell: Set Variable to String, Null (Unset) & Print

In this short note i am showing how to define and print variables is Windows PowerShell.

Particularity i will show how to set a variable to a string value, how to define a variable directly in a string and how to unset variable by setting it to Null.

At the end of the each example the variable will be printed.

Cool Tip: Set environment variables in Windows! Read More →

Set (Unset) Variable in PowerShell

Set variable to string:

PS C:\> $sitename = "ShellHacks"
PS C:\> echo $sitename
ShellHacks

Define variable in a string:

PS C:\> $sitename = "ShellHacks"
PS C:\> $message = "Hello, $name
PS C:\> echo $message
Hello, ShellHacks

Set variable to Null (unset variable)

PS C:\> $var  = $null
PS C:\> echo $sitename
PS C:\>

Cool Tip: Add a directory to Windows %PATH% environment variable! Read More →

Was it useful? Share this post with the world!

Leave a Reply