BeginnerLesson 1 of 16

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?

🌍 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.

🆚
PowerShell vs cmd.exe vs Bash

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.

💡
PowerShell Version Check

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

The PowerShell Object Pipeline
Get-Process
Process objects
Where-Object
Filtered objects
Export-Csv

⌨️ Commands / Syntax

powershell
# 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

  1. Open PowerShell and run $PSVersionTable to see your version, OS, and .NET information.
  2. Run Get-Command -Verb Get | Measure-Object to count available Get-* commands.
  3. Run Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 to see top CPU consumers.
  4. Run Get-Command -Noun Item to see all cmdlets that work with items (files, folders, registry).
  5. Run Get-Help Get-Service -Full | Out-Host -Paging to read complete documentation for Get-Service.
🎮
Try It Yourself

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."

🎯 Interview Questions

Beginner

What is PowerShell?

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.

How is PowerShell different from cmd.exe?

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.

What is the naming convention for PowerShell cmdlets?

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.

What is the difference between Windows PowerShell 5.1 and PowerShell 7?

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.

How do you find help for a cmdlet?

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

Why does PowerShell return objects instead of text?

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.

What is Get-Member and when do you use it?

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.

What is the execution policy and what does RemoteSigned mean?

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.

What is a PowerShell module?

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.

What is PSGallery?

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

A junior engineer says PowerShell is just a fancier command prompt. How do you explain the object pipeline?

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.

A script runs fine on your machine but fails on the build server with an execution policy error. What is your fix?

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.

You need a script to run on both a Windows Azure DevOps agent and a Linux GitHub Actions runner. What do you target?

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.

You discover a .ps1 file on a production server with no documentation. How do you investigate it safely?

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.

You need to audit the PowerShell version on 50 servers at once. How?

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.