100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

PowerShell Scripting Cheat Sheet

PowerShell Scripting Cheat Sheet

Core PowerShell scripting reference covering variables, the object pipeline, control flow, functions, and common cmdlets.

2 PagesBeginnerApr 8, 2026

Basics

Variables and output.

powershell
# Variables and output$name = "World"Write-Host "Hello, $name!"$number = 42Write-Output "Value: $number"Set-StrictMode -Version Latest

The Pipeline

Piping objects between cmdlets.

powershell
Get-Process | Where-Object { $_.CPU -gt 100 }Get-ChildItem -Path C:\Logs -Filter *.logGet-Content .\file.txt -Tail 10$services = Get-Service$services | Sort-Object Status | Select-Object -First 5

Functions

Defining functions with typed parameters.

powershell
function Get-Square {    param(        [Parameter(Mandatory=$true)]        [int]$Number    )    return $Number * $Number}Get-Square -Number 51..5 | ForEach-Object { $_ * 2 } | Where-Object { $_ -gt 4 }

Control Flow

Branching, looping, and error handling.

  • if / elseif / else- if ($x -gt 5) { } elseif ($x -eq 5) { } else { }
  • foreach- foreach ($item in $collection) { } iterates a collection
  • for- for ($i=0; $i -lt 5; $i++) { } classic counting loop
  • switch- switch ($x) { 1 {"one"} default {"other"} } multi-branch match
  • try/catch/finally- Structured error handling around a script block

Common Cmdlets

Frequently used cmdlets.

  • Get-Help <cmdlet> -Full- View full documentation for a cmdlet
  • Get-Command -Verb Get- List cmdlets that use the Get verb
  • Invoke-WebRequest -Uri <url>- Make an HTTP request
  • Import-Module <name>- Load a module into the session
  • New-Item -ItemType Directory -Path .- Create a new file or folder
  • $_- Refers to the current object in the pipeline
Pro Tip

Use approved verb-noun naming (Get-, Set-, New-, Remove-) for custom functions — run Get-Verb to see the approved list — so your cmdlets integrate cleanly with PowerShell's discovery and help system.

Was this cheat sheet helpful?

Explore Topics

#PowerShellScripting#PowerShellScriptingCheatSheet#Programming#Beginner#ThePipeline#Functions#ControlFlow#CommonCmdlets#OOP#DevOps#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet