Free preview.You're sampling one lesson — enroll free to unlock all 7 lessons and track your progress.
Enroll free
lesson

Variables and Logic

Variables and Logic

In this lesson — part of Scripting Basics — you'll learn variables and logic in PowerShell and why it matters in real work.

Why it matters

Variables are how programs remember values — the foundation of every computation.

Key ideas

  • A variable is a name bound to a value
  • Choose clear, descriptive names
  • Constants vs. reassignable variables
  • Values have types

In practice

Here's how it looks in idiomatic PowerShell:

$name = 'Ross'
$count = 42
[int]$typed = '7'        # coerced to int via cast
New-Variable -Name PI -Value 3.14159 -Option ReadOnly
$env:MY_FLAG = 'on'      # environment variable via provider
$null -eq $missing       # null-safe comparison: $null goes on the LEFT
Write-Output "$name has $count items"

PowerShell note: Variables are untyped by default and live in provider drives ($env:, $script:, etc.), and the idiom $null -eq $x (not $x -eq $null) avoids a trap where comparing an array to $null filters the array instead of returning a boolean.

Try it yourself

Exercise: Declare three variables in PowerShell (a name, an age, and whether you're learning) and print them.

Recap

You now understand variables and logic and can apply it in PowerShell. Mark this lesson complete and continue to the next one.