In this lab we’ll utilize the techniques from the previous lessons to:

Let’s start with PowerShell Variables. PowerShell variables will always start with a $. They can contain any object or ‘collection of objects’ returned when you run a cmdlet.

Let’s start with a simple String Object. (We’ll be using PowerShell ISE for this.)

Type:

$mystring = "Praise be to Powershell!"
$mystring

Untitled

In this example, we set the value of $mystring to equal a string value and print it back by typing the variable name.

We can also store returned objects in variables like this:

(Be sure the calculator is closed when you run this!)

$current_processes = get-process
$current_processes 

Untitled

We can now work with this ‘collection’ of objects stored in the $current_processes variable as we would the output of the get-process command itself.

For Example:

$current_processes | select Name,CPU | sort CPU

Untitled

Now start the calculator (do this first). Then we’ll create a variable called $processes_new that contains the collection of objects returned from the get-process cmdlet with the calculator process running.

$processes_new = get-process