Variables and Values

Store values in variables, write text, numbers and dates, keep lists and lookups, and read the environment variables every program can see.

Updated

Values

  1. Variables: `$name` (Apprentice): A variable is a name PowerShell keeps a value under, so $owl = "…" stores a long path once, $drawings = Get-ChildItem … keeps a whole list of files, and $owl hands the value back in any later command until you close the window.
  2. Text: Quotes and `$( )` (Apprentice): Double quotes fill in the values of variables and single quotes keep text exactly as typed, $( ) puts a property or a whole command's answer into text, and a here-string holds text of many lines.
  3. Numbers, Dates and Types (Apprentice): Every value in PowerShell has a type, such as a whole number, text or a date; [int], [decimal] and [datetime] turn text into the type you need, and subtracting dates, AddDays and Get-Date -Format answer questions such as how many days are left until a trip.
  4. Lists and Lookups: Arrays and Hashtables (Journeyman): An array keeps several values in order, made with commas or @( ) and read by position from [0], and a hashtable, made with @{ }, keeps values under names so you can look one up by its name, the way you'd find a word in a dictionary.

The Environment

  1. Environment Variables and `PATH` (Apprentice): Environment variables are settings Windows hands to every program, read and set in PowerShell with $env:, and PATH is the one that lists the folders searched for a command, which is why a program outside them is not recognized until you run it by its path or add its folder for this session.

Exercise: The Workshop's Machines

  1. Exercise: The Workshop's Machines (Apprentice): Mind an inventor's workshop with variables, quotes, dates, arrays, hashtables and environment variables, from counting her machines to oiling the gears by name from your PATH, while a Pester check reads the eight results.