PowerShell Cheat Sheet Apr 5, 2013 Variables $x = 1 New-Variable -Name x -Value 12 Get-Variable x -valueonly Set-Variable -Name x -Value 34 Clear-Variable -Name x Remove-Variable -Name x # Print the value $x # which is an equivalent of: Write-Host $x # Get the type $x.GetType() # Strongly typed [int]$x = 2 # Comparisons $x -eq 20 $x -gt 20 $x -lt 20 References: PowerShell Data Types Comparison Operators Strings $str = 'Text 1' $str2 = "Text 2" # Newline "First line`nSecond line" $multiline = @" Multiline text Anouther line "@ # Single quotes $multiline = @' Multiline text Anouther line '@ # Variables in text $x = 1 $y = 1 "Text with variable $x and $y" # Formatting text [String]::Format("Some text with {0}", $x) # Short version "Some text {0} and {1}" -f $x, $y Arrays and Hash Tables arr = "one", "two", "three" $arr[0] $arr[1] $arr1 = @() $arr1 = @("one", "two") $arr1.Count $arr2 = 1..10 $arr2 -contains 5 $arr2 -notcontains 10 $ht = @{"Name" = "Tom", "Surname" = "Cruise"} $ht["Name"] $ht."Name" $key = "Name" $ht.$key $ht.Remove("Name") $ht.Contains("Name") $ht.ContainsValue("Tom") $ht.Keys $ht.Values Built-in variables $true $false $NULL # Current directory $pwd # Current object $_ Get-ChildItem | Where-Object {$_.Name -like "*.cs"}