cmd.exe manipulates text strings. Bash manipulates text streams, making it excellent for file and string processing on Linux. PowerShell manipulates .NET objects, making it ideal for Windows system state, Azure resources, and structured data. On Windows servers, PowerShell is always the right choice. For cross-platform DevOps work, PowerShell 7 or Bash both work—choose the one your team knows best.
What is PowerShell
Understand why PowerShell is more than a command prompt: how it outputs .NET objects instead of text, why the Verb-Noun convention makes it predictable, and why it became the standard automation shell for Windows, Azure, and DevOps pipelines.
🧒 Simple Explanation (ELI5)
Imagine you manage a school with 500 students. Doing attendance one by one takes hours. PowerShell is like a smart assistant that can handle all 500 students at once, follow instructions in English-like sentences, and repeat the task tomorrow with zero effort. Instead of clicking through menus, you write one command and the computer does it across every machine in your fleet.
🔧 Why Do We Need It?
- Repetition at scale: restarting a service on one server takes two clicks; restarting it on 50 servers takes one PowerShell command.
- Object output: unlike cmd.exe which outputs raw text, PowerShell outputs .NET objects you can filter, sort, and export without text parsing.
- Cross-platform: PowerShell 7+ runs on Windows, Linux, and macOS—same scripts work on build agents of any OS.
- Azure native: the Az module connects PowerShell directly to your Azure subscription for resource management, deployment, and reporting.
- CI/CD integration: Azure DevOps and GitHub Actions both run PowerShell tasks natively, making it the glue between scripts and pipelines.
🌍 Real-world Analogy
Think of PowerShell as a universal remote that speaks the language of every device in your data center. The old command prompt (cmd.exe) only worked for text files on the current machine. PowerShell works for files, services, processes, registry, Active Directory, Azure, and anything else with a .NET library—and can record macros (scripts) to repeat complex sequences with one command.
⚙️ Technical Explanation
PowerShell is a task automation and configuration management shell built on .NET. Windows PowerShell 5.1 ships with Windows and uses the full .NET Framework. PowerShell 7+ is cross-platform, open source, built on .NET Core, and recommended for new work.
Unlike text-based shells, PowerShell passes .NET objects through its pipeline. When you run Get-Process, you receive an array of System.Diagnostics.Process objects with typed properties like CPU, WorkingSet, and Id—not a string you have to parse. This is why you can write Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 without any text manipulation at all.
Run $PSVersionTable.PSVersion to see your current version. If you are on Windows PowerShell 5.1 and targeting Azure or Linux build agents, install PowerShell 7 (winget install Microsoft.PowerShell) and use pwsh to launch it. The module documentation always specifies which version is required.
📊 Visual Representation
⌨️ Commands / Syntax
# Check your PowerShell version $PSVersionTable.PSVersion # List all Get-* commands available on this system Get-Command -Verb Get | Measure-Object # Find cmdlets related to a specific noun Get-Command -Noun Service Get-Command -Noun Process # Read full help for a cmdlet Get-Help Get-Process -Examples # Update help files (run as Administrator) Update-Help # Top 5 processes by CPU usage Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 # List all running services Get-Service | Where-Object Status -eq Running
💼 Example (Real-world Use Case)
A platform team manages 120 Windows servers. Every Monday, an operations engineer needs to confirm disk usage is below 80% on all machines. Before PowerShell, this meant 120 RDP sessions. With PowerShell Remoting and a single script, the same check runs across all machines in under two minutes and outputs a CSV report that gets emailed automatically.
🧪 Hands-on
- Open PowerShell and run
$PSVersionTableto see your version, OS, and .NET information. - Run
Get-Command -Verb Get | Measure-Objectto count available Get-* commands. - Run
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5to see top CPU consumers. - Run
Get-Command -Noun Itemto see all cmdlets that work with items (files, folders, registry). - Run
Get-Help Get-Service -Full | Out-Host -Pagingto read complete documentation for Get-Service.
Run Get-Process | Group-Object Company | Sort-Object Count -Descending | Select-Object -First 10. This groups all running processes by their publisher name and shows who the top process owners are. This is a real sysadmin technique for spotting unexpected software running in an environment.
🐛 Debugging Scenario
Problem: you run powershell -File deploy.ps1 and get: "File cannot be loaded because running scripts is disabled on this system."
- Cause: Windows default execution policy is
Restricted, which blocks all .ps1 files regardless of source. - Diagnose: run
Get-ExecutionPolicy -Listto see the policy at every scope (Machine, User, Process). - Safe fix: run as Administrator:
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine. This allows local scripts and remote scripts with a valid signature. - One-off fix:
powershell -ExecutionPolicy Bypass -File deploy.ps1for a single invocation without changing the machine policy. - Do not use:
Set-ExecutionPolicy Unrestrictedin production. It removes all safety checks on downloaded scripts.
🎯 Interview Questions
Beginner
PowerShell is a cross-platform automation shell and scripting language built on .NET. It outputs .NET objects instead of text, uses a Verb-Noun naming convention, and integrates with Windows, Azure, and CI/CD pipelines.
cmd.exe outputs plain text. PowerShell outputs .NET objects with properties you can filter, sort, and export without manually parsing strings. PowerShell also has structured error handling, modules, and a cross-platform version.
Verb-Noun: the verb describes the action (Get, Set, New, Remove, Start, Stop) and the noun describes the target (Process, Service, Item, ADUser). This makes commands self-descriptive and discoverable with Get-Command.
Windows PowerShell 5.1 ships with Windows and uses the .NET Framework. PowerShell 7 is cross-platform (Windows, Linux, macOS), open source, built on .NET Core, and maintained actively. PowerShell 7 is the recommended version for new automation work.
Use Get-Help Get-Process -Examples for examples, Get-Help Get-Process -Full for complete documentation, or Get-Help Get-Process -Online to open the Microsoft docs page.
Intermediate
Because .NET objects have typed properties. You can pipe them to Where-Object to filter, Sort-Object to sort, or Select-Object to pick properties—without regular expressions or awk. This makes data manipulation far more reliable and readable.
Get-Member lists all properties and methods on an object. You run Get-Process | Get-Member to discover that process objects have CPU, Id, Name, WorkingSet64, and dozens more properties you can filter and sort on.
Execution policy controls which scripts PowerShell will run. RemoteSigned allows locally written scripts without a signature and requires downloaded/remote scripts to be digitally signed by a trusted publisher. It is the recommended setting for most production machines.
A module is a package of PowerShell code (cmdlets, functions, variables) that can be imported and reused. The Az module provides Azure management cmdlets. Modules are installed from PSGallery with Install-Module and imported with Import-Module.
PSGallery (PowerShell Gallery) is the official public repository for PowerShell modules and scripts. You install modules from it using Install-Module -Name Az. It is the equivalent of npm for Node or pip for Python.
Scenario-based
Ask them to get disk usage from 10 servers using cmd.exe and extract the free space as a number. Then show the same task in PowerShell with Get-PSDrive piped to Where-Object and Sort-Object. The difference between parsing text and working with structured objects makes the point quickly.
First run Get-ExecutionPolicy -List on the build server to see which scope is restrictive. For CI/CD, the standard secure fix is to add -ExecutionPolicy Bypass only at the process scope in the pipeline task, or set RemoteSigned at machine scope during agent provisioning.
Target PowerShell 7 (pwsh) and avoid Windows-only cmdlets like Get-WmiObject (use Get-CimInstance instead), avoid .NET APIs that lack Linux support, and test on both platforms. The pipeline YAML specifies the shell as pwsh.
Read it with Get-Content script.ps1 first. Look for param() blocks, #Requires statements, and external calls. Use -WhatIf against any destructive commands before running. Check with Get-AuthenticodeSignature script.ps1 to see if it is signed. Never run unknown scripts with elevated privileges without a code review.
Use Invoke-Command -ComputerName (Get-Content servers.txt) -ScriptBlock { $PSVersionTable.PSVersion }. This runs the version check on all servers in parallel via WinRM and returns the results as objects you can then export to CSV.
🌐 Real-world Usage
System administrators use PowerShell to provision Active Directory users in bulk, enforce security baselines across Windows fleets, generate compliance reports, and rotate credentials. DevOps engineers run PowerShell inside Azure DevOps YAML tasks to deploy ARM templates, configure Azure resources, and validate infrastructure gates before releases reach production.
📝 Summary
PowerShell is a cross-platform, object-based automation shell built on .NET. It uses Verb-Noun naming for predictability, passes typed objects through the pipeline instead of text, and integrates natively with Windows administration, Azure, and CI/CD pipelines. PowerShell 7 is the modern cross-platform version. Its key advantage over other shells is that you work with structured data from the first command—no text parsing required.