PowerShell — Object-Based Shell and Scripting Language from Microsoft

Practical guide to PowerShell — cmdlets, the object-based pipeline, processes, services and scripts across platforms with pwsh 7.

PowerShell is more than a shell: its pipeline passes real .NET objects rather than plain text lines – the key difference from bash. Commands follow the clear Verb-Noun scheme like Get-Process or Get-ChildItem, and Get-Help plus Get-Command let you discover the rest yourself. Since PowerShell 7 (pwsh) it runs cross-platform on Windows, Linux and macOS. This guide covers the cmdlets for navigation, processes, the pipeline and scripting that you reach for every day.

Basics & Navigation

Get-Location — Show the current directory (alias: pwd).

Get-Location

Set-Location <path> — Change directory (alias: cd).

Set-Location C:\Users

Get-ChildItem — List files and directories (alias: ls, dir).

Get-ChildItem -Recurse -Filter *.log

Get-Content <file> — Display file contents (alias: cat, type).

Get-Content C:\logs\app.log -Tail 20

Get-Command <name> — Find commands by name or pattern.

Get-Command *-Service

Get-Help <cmdlet> — Show help for a cmdlet.

Get-Help Get-Process -Examples

Get-Alias <alias> — Show what a command alias maps to.

Get-Alias ls

Processes & Services

Get-Process — List all running processes.

Get-Process | Sort-Object CPU -Descending | Select -First 10

Stop-Process -Name <name> — Kill a process by name.

Stop-Process -Name notepad

Stop-Process -Id <pid> — Kill a process by PID.

Stop-Process -Id 1234 -Force

Get-Service — List all services.

Get-Service | Where-Object Status -eq Running

Start-Service <name> — Start a service.

Start-Service -Name wuauserv

Stop-Service <name> — Stop a service.

Stop-Service -Name Spooler

Restart-Service <name> — Restart a service.

Restart-Service -Name nginx

Files & Text

Copy-Item <src> <dest> — Copy files or directories (alias: cp, copy).

Copy-Item -Path .\config -Destination .\backup -Recurse

Move-Item <src> <dest> — Move or rename files (alias: mv, move).

Move-Item old.txt new.txt

Remove-Item <path> — Delete files or directories (alias: rm, del).

Remove-Item -Path .\temp -Recurse -Force

New-Item -ItemType File <name> — Create a new file.

New-Item -ItemType File -Name config.json

New-Item -ItemType Directory <name> — Create a new directory (alias: mkdir).

New-Item -ItemType Directory -Name logs

Select-String -Pattern '<regex>' -Path <files> — Search for text in files (like grep).

Select-String -Pattern 'error' -Path *.log -CaseSensitive

Pipeline & Filtering

| Where-Object { <condition> } — Filter objects in the pipeline.

Get-Process | Where-Object { $_.CPU -gt 100 }

| Select-Object <properties> — Select specific properties from objects.

Get-Process | Select-Object Name, CPU, WorkingSet | Sort-Object CPU -Descending

| Sort-Object <property> — Sort objects by a property.

Get-ChildItem | Sort-Object Length -Descending

| Format-Table — Display output as a table.

Get-Service | Format-Table Name, Status, StartType

| Format-List — Display output as a detailed list.

Get-Process explorer | Format-List *

| Measure-Object — Count, sum, average, min, max of objects.

Get-ChildItem *.log | Measure-Object -Property Length -Sum

| Export-Csv <file> — Export pipeline output to CSV.

Get-Process | Export-Csv processes.csv -NoTypeInformation

| ConvertTo-Json — Convert output to JSON format.

Get-Service | ConvertTo-Json | Out-File services.json

System & Network

Get-ComputerInfo — Show detailed system information.

Get-ComputerInfo | Select OsName, OsVersion, CsTotalPhysicalMemory

Get-NetIPAddress — Show IP addresses of all network interfaces.

Get-NetIPAddress -AddressFamily IPv4

Test-NetConnection <host> -Port <port> — Test network connectivity (like telnet/ping).

Test-NetConnection google.com -Port 443

Invoke-WebRequest <url> — Download a web page or file (alias: curl, wget).

Invoke-WebRequest -Uri https://example.com -OutFile page.html

Invoke-RestMethod <url> — Call a REST API and parse the JSON response.

Invoke-RestMethod -Uri https://api.github.com/repos/microsoft/terminal

Get-WinEvent -LogName System -MaxEvents 20 — Show recent event log entries (Windows).

Get-WinEvent -LogName System -MaxEvents 20

Variables & Scripting

$variable = <value> — Set a variable.

$name = 'World'; Write-Host "Hello $name"

$env:<VAR> — Access environment variables.

$env:PATH; $env:COMPUTERNAME

if (<condition>) { } else { } — Conditional execution.

if (Test-Path .\config.json) { 'Found' } else { 'Missing' }

foreach ($item in $collection) { } — Loop over a collection.

foreach ($f in Get-ChildItem *.txt) { Write-Host $f.Name }

Set-ExecutionPolicy RemoteSigned — Allow running local scripts (required once).

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

.\<script>.ps1 — Run a PowerShell script.

.\deploy.ps1

Conclusion

PowerShell combines an interactive shell with a full scripting language – once the object-based pipeline model clicks, you filter and format data with Where-Object, Select-Object and Format-Table far more precisely than with plain text processing. For cross-platform work, reach for PowerShell 7 (pwsh); the older Windows PowerShell 5.1 stays Windows-only and carries legacy cmdlets like Get-EventLog. Mind the execution policy: RemoteSigned is a sensible default that allows local scripts but requires downloaded ones to be signed – don't reach for Bypass or Unrestricted lightly, and review third-party scripts before you run them.

Further Reading

  • bash – the GNU Bourne-Again Shell, the default shell on Linux
  • zsh – the Z shell with advanced completion and plugins
  • wsl – Windows Subsystem for Linux, bridging PowerShell and Linux shells