Variables, Data Types and Operators
Harry
· 13 Sep 2026
· 1 views
Variables and Types
$name = 'Har' # string
$age = 30 # int
$price = 9.99 # double
$active = $true # bool
$list = @('a','b','c') # array
$map = @{ name = 'Har'; role = 'Admin' }Strong Typing
[int]$count = 3
[string]$title = 'Grails'
[int]'42' # cast a string to int
"Value: $count" # interpolation in double quotesOperators
1 -lt 2 # less than
$name -like 'Har*'
$list -contains 'b'
-matches, -and, -or, -notSpecial Variables
$_ current pipeline object, $args script arguments, $error last error, $env:PATH environment variable:
$env:JAVA_HOME
$error[0] | Format-List * -ForceScope
Script: and Global: prefix variables to lift them out of function scope. $global:config = 1 persists for the session.
Key Points
- Variables carry typed .NET objects.
- Double quotes interpolate, single quotes are literal.
- -like/-contains/-matches are PowerShell operators.
- Scopes control where variables live.