AUTOMATION TOOL

Make your computer do the hard work for you.

PowerShell is a typing tool. Instead of clicking through menus to fix a computer, you type one line of text, and the computer does exactly what you say. It saves time and stops mistakes.

Clicking vs. Typing

The Slow Way (Clicking)

  • 1. Open the Start Menu
  • 2. Search for "Control Panel"
  • 3. Click "Network Settings"
  • 4. Click "Adapter Options"
  • 5. Find your IP address

The Fast Way (PowerShell)

Just type this and hit Enter:

Get-NetIPAddress

Done in 2 seconds.

How to speak the language

PowerShell uses a very simple naming rule. Every action is built like a tiny sentence. We call these commands Cmdlets (pronounced "Command-Lets"). They always follow the rule: Action - Thing.

VERB (Action)
NOUN (Thing)
Get-Process Shows running apps.
Stop-Service Turns off a background job.
New-Item Creates a new file or folder.

Smart Blocks, Not Just Words

Old computer systems just spit out lines of text. PowerShell is smarter. It gives you "Objects." An object is like a smart box that holds many facts inside it.

Dumb Text

It just looks like the word "Apple". You can only read it.

Apple

Smart Object

It is a box labeled "Apple" that knows its own facts.

Box: Apple
Color: Red
Weight: 150g
Taste: Sweet

The Pipeline: Passing the Baton

Because PowerShell uses smart boxes (objects), you can pass a box from one command to the next using a straight line called a Pipeline ( | ).

Get-Process
Gets all running apps
|
Sort CPU
Sorts apps by power used
|
Stop-Process
Kills the heaviest app

Variables: Saving Things for Later

Sometimes you want to save an answer so you can use it again in five minutes. In PowerShell, you put a dollar sign ($) in front of a word to create a saving box, called a Variable.

  • The $ tells the computer: "Hey, remember this."
  • You can save a word, a number, or a whole smart object.
  • You can name it almost anything you want.
# 1. We save a name
$MyName = "Alex"
# 2. We ask the computer to say hello
Write-Host "Hello, " + $MyName
# 3. What the computer shows:
Hello, Alex

Scripts: Doing Many Things at Once

If you have to type the same five commands every morning, you will get bored. Instead, you can save those five commands into a text file. This file is called a Script.

The Automation Goal

You double-click the script file. The computer runs all five commands instantly. You go drink coffee while the computer does your morning work for you.

PowerShell scripts usually end with .ps1 (Example: SetupComputer.ps1)

It Works Everywhere Now

A long time ago, PowerShell only worked on Microsoft Windows. Not anymore. Microsoft made it open to the world. Now you can use the exact same skills on almost any computer.

Windows

It comes built-in. It is the boss of Windows.

Mac

You can download it and manage your Apple files easily.

Linux

Servers run it to automate big web systems.

3 Easy Things You Can Try Today

1. See what is slowing down your PC

Find out what programs are using the most memory.

Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 5

2. List all files in a folder

See exactly what is inside your documents folder.

Get-ChildItem -Path "C:\Users\YourName\Documents"

3. Check exactly how long your PC has been on

Find the exact start time of your computer.

(Get-CimInstance Win32_OperatingSystem).LastBootUpTime

Shortcuts for Fast Typers

Typing Get-ChildItem every time you want to see your files gets annoying. PowerShell has built-in nicknames for long commands. These are called Aliases.

dir
Get-ChildItem
cd
Set-Location
kill
Stop-Process
echo
Write-Output

Finding the Needle in the Haystack

If you ask for a list of computer parts, you might get 1,000 items. To only see the ones you care about, we use a filter called Where-Object.

"Get all the running programs, BUT ONLY keep the ones using more than 100MB of memory."
Get-Process | Where-Object WorkingSet -GreaterThan 100MB

Making the Answers Look Good

Sometimes the computer spits out too much data. You can force PowerShell to organize the smart objects into a clean table or a simple list.

Format-Table

Lines up the facts in neat columns.

Name        Status
Chrome      Running
Spotify     Running

Format-List

Shows one item at a time, listing every fact top to bottom.

Name: Chrome
Status: Running
Name: Spotify
Status: Running

Instant Reports for Your Boss

You gathered all this data, now you need to put it in an Excel file. Instead of copy-pasting, just add one more pipe to the end of your command: Export-Csv.

Get-Process | Export-Csv -Path "C:\Report.csv"
SPREADSHEET CREATED

Modules: Adding New Tools

PowerShell comes with basic tools. But what if you want to manage Amazon Web Services, or Microsoft Teams? You just download a new box of tools. These boxes are called Modules.

1. Find a tool online
Find-Module -Name "Az"
2. Install it
Install-Module "Az"
3. Use the new tools
Get-AzVM

The "Do It 100 Times" Button

If you have to rename 100 files, do not do it by hand. Use a loop. The ForEach-Object command takes a list of things and performs the exact same action on every single one of them.

Computers never get tired. Let them do the boring repetition.

# For every file in the folder...
Get-ChildItem | ForEach-Object {
# ...Add the word 'OLD_' to the name
Rename-Item $_.Name "OLD_$($_.Name)"
}

The Safety Switch (-WhatIf)

Before you hit Enter on a command that deletes files or shuts down servers, you might feel scared. What if you made a typo? Just add -WhatIf to the end.

Stop-Computer -WhatIf
What if: Performing the operation "Stop-Computer" on target "Server01".

* The computer didn't actually turn off. It just told you what WOULD happen.

Why is my script blocked?

You wrote your first script, double-clicked it, and got a big red error saying it is "disabled." Don't panic. Windows has a built-in security guard called the Execution Policy to stop bad viruses from running silently.

Restricted (Default)

The guard says: "No scripts allowed at all. You can only type commands one by one."

EASY FIX

RemoteSigned

The guard says: "You can run your own scripts, but scripts from the internet need a digital signature."

Set-ExecutionPolicy RemoteSigned

Fixing Computers from your Couch

If someone in the other building has a broken computer, you don't need to walk over there. You can use PowerShell Remoting to secretly connect to their computer in the background without interrupting their work.

# 1. Knock on their computer's door
Enter-PSSession -ComputerName "Reception-PC"

# 2. Your black screen now controls their PC!
[Reception-PC]: Restart-Service PrinterSpooler

Your Personal Setup (Profiles)

A Profile is simply a script that runs automatically every single time you open PowerShell.

If you always want your background to be red, or if you always want to load your favorite shortcuts, you put those instructions in your Profile file. It sets up your desk exactly how you like it before you even start working.

Type $PROFILE and press enter to see exactly where your personal setup file lives on your hard drive.

Custom Look

Make it yours. Change colors, text sizes, and starting folders automatically.

Don't know what to do? Just ask.

PowerShell comes with a massive built-in instruction manual. If you ever forget how a command works, you don't even need to use the internet. Just ask PowerShell directly using Get-Help.

Get-Help Get-Process -Examples