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 quotes

Operators

1 -lt 2       # less than
$name -like 'Har*'
$list -contains 'b'
-matches, -and, -or, -not

Special Variables

$_ current pipeline object, $args script arguments, $error last error, $env:PATH environment variable:

$env:JAVA_HOME
$error[0] | Format-List * -Force

Scope

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.
Share this post:

Comments (0)

Please login or register to comment.