Introduction to PowerShell

The Command That Changed Everything

Three years ago, I was managing server configurations the hard way - Remote Desktop sessions, clicking through GUI wizards, manually updating registry keys, and documenting changes in a Word document that nobody read. One misconfigured setting could take hours to diagnose and fix across dozens of servers.

During a critical security patch deployment, I needed to verify a specific registry setting across 80 Windows servers. My plan: open Remote Desktop to each server, navigate to the registry, check the value, record it in Excel. Estimated time: 6-8 hours.

My colleague walked by, saw what I was doing, and said "Give me 30 seconds." He opened PowerShell and ran:

Invoke-Command -ComputerName (Get-Content servers.txt) -ScriptBlock {
    Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion' -Name ProgramFilesDir
} | Select-Object PSComputerName, ProgramFilesDir | Export-Csv results.csv

Thirty seconds later, he had a CSV file with the results from all 80 servers. That was my PowerShell awakening.

What is PowerShell?

PowerShell is a cross-platform task automation and configuration management framework from Microsoft, consisting of a command-line shell and scripting language. Unlike traditional shells that work with text, PowerShell works with objects - structured data that you can manipulate, filter, and transform with incredible precision.

PowerShell vs Traditional Shells

Traditional shells (Bash, Command Prompt):

  • Work with text streams

  • Require parsing with tools like grep, awk, sed

  • Platform-specific (Bash on Linux/Mac, CMD on Windows)

PowerShell:

  • Works with .NET objects

  • Built-in filtering, sorting, and formatting

  • Cross-platform (Windows, macOS, Linux)

  • Designed for automation and scripting

PowerShell Core vs Windows PowerShell

There are two main versions:

Windows PowerShell 5.1 (pre-installed on Windows):

  • Windows-only

  • Built on .NET Framework

  • No longer receiving new features

  • Still widely used in enterprise environments

PowerShell 7+ (PowerShell Core):

  • Cross-platform (Windows, macOS, Linux)

  • Built on .NET Core/.NET

  • Actively developed with new features

  • Recommended for new projects

This series focuses on PowerShell 7+, but most concepts apply to Windows PowerShell 5.1 as well.

Why PowerShell Matters

1. Automation at Scale

Manual tasks that take hours can be scripted in minutes:

  • Deploying configurations to hundreds of servers

  • Processing thousands of files

  • Managing user accounts in bulk

  • Generating reports from multiple data sources

2. Consistency and Repeatability

Scripts ensure tasks are performed the same way every time:

  • No missed steps

  • No typos in critical configurations

  • Version-controlled processes

  • Documented in code

3. Time Savings

Real examples from my experience:

  • Monthly user access report: 4 hours β†’ 5 minutes

  • Server health checks: 2 hours β†’ 30 seconds

  • Log file analysis: 3 hours β†’ 2 minutes

  • Azure resource deployment: 45 minutes β†’ 5 minutes

4. Cross-Platform Capability

One language for multiple platforms:

  • Windows server management

  • Linux container deployments

  • macOS development environments

  • Cloud infrastructure (Azure, AWS, GCP)

Installing PowerShell

Windows

PowerShell 5.1 is pre-installed. To install PowerShell 7+:

  1. Run the MSI installer

  2. PowerShell 7+ installs alongside Windows PowerShell (both available)

Or use WinGet:

macOS

Using Homebrew:

Linux (Ubuntu/Debian)

Verifying Installation

Launch PowerShell and check the version:

You should see output showing PowerShell version 7.x or higher.

Your First PowerShell Commands

Let's run some basic commands to get comfortable:

Getting System Information

Getting Help

PowerShell has excellent built-in help:

Discovering Commands

Running Your First Practical Command

Let's get a list of running processes:

You'll see structured output showing all running processes with properties like CPU usage, memory, and process ID.

Now let's filter it to find specific processes:

PowerShell Philosophy: Objects Over Text

This is the key concept that makes PowerShell powerful. When you run Get-Process, you're not getting formatted text - you're getting process objects with properties you can access:

Compare this to traditional shells where you'd need to parse text with grep and awk. PowerShell gives you structured data immediately.

PowerShell in Action: Real-World Example

When I was troubleshooting a performance issue, I needed to find which processes were consuming the most CPU over time. Instead of opening Task Manager and manually watching, I wrote:

This script took 10 snapshots over 20 seconds, showing me the pattern I needed to identify the problematic process. Without PowerShell, this would have required manual observation or expensive monitoring tools.

Setting Up Your PowerShell Environment

  1. Install Visual Studio Code

  2. Install the PowerShell extension

  3. Open a .ps1 file or create a new one

  4. Use F5 to run scripts and F8 to run selected code

Benefits:

  • IntelliSense (auto-completion)

  • Syntax highlighting

  • Integrated terminal

  • Debugging capabilities

Using PowerShell ISE (Windows Only)

PowerShell ISE (Integrated Scripting Environment) is built into Windows but is deprecated in favor of VS Code. It still works for basic scripting but lacks modern features.

Using the Terminal

On any platform, simply type pwsh to launch PowerShell 7+ or powershell for Windows PowerShell.

Execution Policies (Windows)

Windows has security settings that may prevent script execution. To check:

For development, you might need to set it to RemoteSigned:

This allows locally-created scripts to run while requiring downloaded scripts to be signed.

Note: Execution policies are not security boundaries - they're safety features to prevent accidental script execution.

Common Pitfalls

1. Confusing PowerShell Versions

Problem: Running scripts designed for PowerShell 7+ in Windows PowerShell 5.1 Solution: Always check $PSVersionTable and specify required versions in scripts

2. Not Using the Help System

Problem: Guessing command syntax instead of using Get-Help Solution: Make Get-Help -Examples your first stop for any new command

3. Expecting Text-Based Output

Problem: Trying to parse PowerShell output like Bash text Solution: Use object properties and methods instead of string parsing

4. Running Dangerous Commands Without Testing

Problem: Running Remove-Item or similar commands without validation Solution: Use -WhatIf parameter to preview changes:

Key Takeaways

  • PowerShell is object-oriented, not text-based like traditional shells

  • PowerShell 7+ is cross-platform and the recommended version

  • Get-Help is your friend - comprehensive documentation built-in

  • Commands follow Verb-Noun naming - making them discoverable

  • Start simple - you don't need to learn everything at once

  • Automation saves time - even simple scripts provide massive value

What You've Learned

βœ… What PowerShell is and why it's different from other shells βœ… The difference between PowerShell Core and Windows PowerShell βœ… How to install PowerShell on your platform βœ… Basic commands to get started βœ… How to use the help system and discover commands βœ… The object-oriented nature of PowerShell

Next Steps

Now that you understand what PowerShell is and have it installed, the next step is learning how PowerShell commands work. In PowerShell Basics and Cmdlets, you'll discover:

  • The Verb-Noun naming convention

  • How to use Get-Command to find what you need

  • Mastering Get-Help for self-sufficiency

  • Understanding cmdlet parameters and syntax

The real power of PowerShell comes from knowing how to find and use the right commands - that's what we'll cover next.


Ready to dive deeper? Continue to PowerShell Basics and Cmdlets β†’

Last updated