PowerShell Basics

💤0
Lv 10 XP
← ⚙️ Scripting & Automation · PowerShell

PowerShell Basics

Beginner ⭐ 50 XP ⏱ 18 min #powershell#scripting#windows

Learn PowerShell's verb-noun cmdlets and object-based approach to automation.

📖Theory

PowerShell is a cross-platform shell and scripting language built on .NET. Its commands are cmdlets named with a consistent Verb-Noun pattern (Get-Process, Set-Item, Remove-Item) so they’re discoverable and predictable.

The big idea that sets it apart from Bash: the pipeline passes objects, not text. Get-Process returns rich process objects with properties you can filter and sort directly — no fragile text parsing with awk/sed.

  • Variables start with $: $name = "Alex"
  • Discover anything with Get-Command, Get-Help, Get-Member
  • Aliases ease the transition: ls, cd, cat map to cmdlets
🌍Real-World Example
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5
Get-ChildItem -Recurse -Filter *.log | Measure-Object -Property Length -Sum
$name = "Alex"
Write-Output "Hello, $name"
Get-Service | Where-Object Status -eq 'Running'
Get-Process | Get-Member          # discover available properties/methods
✍️Hands-On Exercise
  1. Use Get-Process to list the five processes using the most memory.
  2. Find every cmdlet containing “Service” with Get-Command *Service*.
  3. Pipe a cmdlet into Get-Member and read its properties.
  4. Store a value in a variable and interpolate it in a string.
🧾Cheat Sheet
TaskCmdlet
List processesGet-Process
List filesGet-ChildItem
FilterWhere-Object { … }
Pick columnsSelect-Object
SortSort-Object
AggregateMeasure-Object
DiscoverGet-Command, Get-Help, Get-Member
💬Common Interview Questions
How does the PowerShell pipeline differ from Bash?

PowerShell passes structured .NET objects between cmdlets, so you filter and sort by named properties. Bash pipes plain text that must be parsed with tools like awk.

What is the naming convention for cmdlets?

Verb-Noun, like Get-Process or Remove-Item, which makes commands consistent and discoverable via Get-Command and Get-Verb.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type