🔷 PowerShell

PowerShell Fundamentals: Cmdlets, Variables & Piping

📅 July 04, 202610 min readITVedas

PowerShell is Microsoft's automation and configuration management framework. Learn cmdlets, variables, object piping, and data types—the foundation for Windows Server and Azure automation.

INTERMEDIATE
⏱ 10 min read
Prerequisites:
Key Facts
  • PowerShell is built on .NET Framework and provides access to Windows Management Instrumentation (WMI)
  • Over 2,400 cmdlets available in PowerShell 7+ across 137 modules
  • Cmdlet naming follows Verb-Noun convention (Get-Process, Set-Item, Remove-File)
  • PowerShell objects carry metadata, unlike traditional shell output (text only)

What is PowerShell?

PowerShell is a task automation and configuration management framework from Microsoft. Unlike traditional shells (cmd.exe, Bash) that output text, PowerShell outputs objects—structured data with properties and methods. This fundamental difference makes PowerShell exceptionally powerful for system administration.

When you run Get-Process, you don't get text to parse. You get Process objects with properties like Name, ID, Memory, and methods like Kill() or Suspend(). You can filter, sort, and manipulate these objects programmatically.

Cmdlets: The Building Blocks

Cmdlets (pronounced "command-lets") are lightweight commands that perform a single function. They follow a Verb-Noun naming convention:

This consistency makes PowerShell intuitive. If you know Get-Process, you can guess that Get-Service retrieves services and Get-ChildItem lists files.

# Get all running processes sorted by memory
Get-Process | Sort-Object Memory -Descending | Select-Object Name, Memory

# Start the Windows Update service
Start-Service -Name wuauserv

# Get all users in Active Directory
Get-ADUser -Filter * | Select-Object Name, SamAccountName

# Create a new file
New-Item -Path "C:\temp\test.txt" -ItemType File

Variables and Data Types

PowerShell variables start with $ and can store any data type. PowerShell automatically detects the type:

# String variable
$name = "John"

# Integer variable
$age = 30

# Array of servers
$servers = @("server1", "server2", "server3")

# Hashtable (dictionary)
$user = @{
  Name = "John Doe"
  Department = "IT"
  Salary = 75000
}

# Accessing hashtable values
Write-Host $user.Name
Write-Host $user["Department"]

Piping: The Power of PowerShell

The pipe operator | passes objects from one cmdlet to the next. This is the secret to PowerShell's power. Each cmdlet receives the output object and can filter, transform, or act on it.

# Pipe Get-Process to Where-Object to filter
Get-Process | Where-Object {$_.Memory -gt 100MB}

# Pipe to Select-Object to choose specific properties
Get-ADUser -Filter * | Select-Object Name, SamAccountName, EmailAddress

# Pipe to ForEach-Object to perform action on each item
Get-ChildItem C:\temp | ForEach-Object {Remove-Item $_.FullName -Force}

# Chain multiple pipes
Get-Service | Where-Object {$_.Status -eq "Running"} | Sort-Object Name | Select-Object Name, Status

Common Cmdlets for System Administration

File System:

Process Management:

Service Management:

Getting Help in PowerShell

PowerShell has built-in help documentation accessible via the Get-Help cmdlet:

# Get help for a cmdlet
Get-Help Get-Process

# Show detailed help with examples
Get-Help Get-Process -Detailed

# Show only examples
Get-Help Get-Process -Examples

# Search for cmdlets matching a pattern
Get-Command *service*

Key Takeaways

  • PowerShell outputs objects, not text, enabling powerful filtering and manipulation
  • Cmdlets follow Verb-Noun naming convention, making them intuitive and discoverable
  • Variables store data; common types include strings, integers, arrays, and hashtables
  • The pipe operator | chains cmdlets together, passing objects between them
  • Master basic cmdlets for file management, processes, and services to automate daily tasks