breakfixlearn.com

IT-03IT Support

PowerShell for help desk

Use this when: you fix accounts, services and network problems faster from a prompt than from five consoles.

IT-03 PowerShell for help desk cheat sheet. Every table on it is repeated as text below.
Tap the sheet for the full-size image. The text version below is screen-reader friendly.

Text version

Everything on the sheet, as plain HTML: handy for screen readers, copy-paste and search.

How a command reads

PowerShell commands are Verb-Noun, then parameters, and you can pipe one into the next. Examples: Get-Service -Name Spooler | Restart-Service and Get-Process | Sort-Object CPU -Descending.

CommandWhat it does
Get-Command *dns*Find a command
Get-Help Restart-Service -ExamplesShow examples
Get-Service | Get-MemberSee an object's properties
$PSVersionTable.PSVersionWhich PowerShell version

Accounts

These need the ActiveDirectory module from RSAT. Set $pw = Read-Host -AsSecureString before the reset.

CommandWhat it does
Get-ADUser jdoe -Properties LockedOutIs the account locked?
Search-ADAccount -LockedOutList all locked accounts
Unlock-ADAccount -Identity jdoeUnlock
Set-ADAccountPassword jdoe -Reset -NewPassword $pwReset the password
Set-ADUser jdoe -ChangePasswordAtLogon $trueForce a change at next sign-in

This PC

CommandWhat it does
Get-ComputerInfoOS and specs
Get-HotFixInstalled patches
Get-VolumeFree disk space
Get-ServiceServices
Get-ProcessProcesses

Network

CommandWhat it does
Get-NetIPConfigurationIP, gateway and DNS
Test-NetConnection 192.0.2.10 -Port 443Is the port open?
Resolve-DnsName example.comDNS answer
Clear-DnsClientCacheFlush the DNS cache

Event logs

Errors from the System log in the last 24 hours: Get-WinEvent -FilterHashtable @{LogName='System'; Level=2; StartTime=(Get-Date).AddHours(-24)} -MaxEvents 20. Level 1 is critical, 2 error, 3 warning. Get-EventLog works in Windows PowerShell 5.1 only.

Pipeline and remote

Stopped services to a CSV: Get-Service | Where-Object Status -eq 'Stopped' | Select-Object Name, Status | Sort-Object Name | Export-Csv stopped.csv. Add -WhatIf to preview and -Confirm to ask first.

CommandWhat it does
Enter-PSSession -ComputerName PC01Open a remote prompt
Invoke-Command PC01 { Get-Service }Run a command remotely

Ticket recipes

TicketCommand
Printer stuckRestart-Service Spooler
"Did you restart?"(Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
Disk fullGet-Volume | Select-Object DriveLetter, SizeRemaining

Run it safely

Danger. Never put a password in a script. Set $pw = Read-Host -AsSecureString first.

Caution. Stop-Process, Remove-Item and Restart-Computer act at once. Try -WhatIf first.

Caution. Read a script before you run it.

Remember

  • Open PowerShell as admin only for admin tasks
  • Get- reads; Set- changes
  • Tab completes names and parameters

Sources

Go deeper on the blog