Skip to content

PowerShell

Using PowerShell for Windows and server administration.

Why It Matters

PowerShell is the standard way to administer Windows at scale. Anything done once in a console can be scripted, repeated across many machines, and scheduled, which is the difference between managing ten servers and managing hundreds.

Reference

Essentials

Get-Help <cmdlet> -Full          # help for a command
Get-Command *service*            # discover commands
Get-Member                       # inspect an object's properties and methods
<cmdlet> | Format-Table -Auto    # readable output
<cmdlet> | Export-Csv out.csv -NoTypeInformation

Execution Policy

Get-ExecutionPolicy -List
Set-ExecutionPolicy -Scope Process RemoteSigned   # for the current session only

Remoting

Enter-PSSession -ComputerName SERVER01
Invoke-Command -ComputerName SERVER01 -ScriptBlock { Get-Service }

Download a File

$URL  = "http://example.com/file.txt"
$Path = "C:\Users\me\Downloads\file.txt"
Invoke-WebRequest -Uri $URL -OutFile $Path

How I Use It

I write small, single-purpose functions and keep the useful ones in the scripts library. Get-Help, Get-Command, and Get-Member are how I work out an unfamiliar object or module rather than searching the web. Remoting and Invoke-Command turn a one-host task into a fleet task.

Resources