PowerShell Reference
Free reference guide: PowerShell Reference
About PowerShell Reference
The PowerShell Reference is a comprehensive, searchable guide covering all essential aspects of PowerShell scripting and system administration. It is organized into eight categories: Basic Syntax (variables, arrays, hashtables, conditionals, loops, comparison and logical operators), Cmdlets (Get-Process, Get-Service, Get-ChildItem, Get-Content, Select-Object, Where-Object), Variables (environment variables, type casting, special variables like $_, $null, $PSVersionTable), Pipeline (|, ForEach-Object, Sort-Object, Measure-Object, Group-Object, Export-Csv), Functions (function definition, param() blocks, CmdletBinding, begin/process/end), Modules, Remoting, and Objects.
Windows system administrators, DevOps engineers, and cloud engineers use this reference for automating Windows administration tasks, managing Azure infrastructure with the Az module, building CI/CD pipelines, and processing structured data from APIs or log files. PowerShell's object-based pipeline — where cmdlets pass .NET objects rather than text — distinguishes it from bash and enables powerful data transformation without string parsing.
This reference covers both Windows PowerShell 5.1 and PowerShell 7+ (cross-platform). Each entry includes the full syntax with parameter examples and a realistic code snippet demonstrating the command in a real-world context such as filtering processes by CPU usage, exporting service status to CSV, running commands on multiple remote servers, or serializing data to JSON for API consumption.
Key Features
- Basic syntax: variable assignment, @() arrays, @{} hashtables, if/elseif/else, switch, for/foreach/while
- Comparison operators: -eq, -ne, -gt, -lt, -ge, -le; logical operators: -and, -or, -not
- Core cmdlets: Get-Process, Get-Service, Get-ChildItem, Get-Content, Set-Content, Select-Object, Where-Object
- Pipeline operators: |, ForEach-Object, Sort-Object, Measure-Object, Group-Object, Export-Csv/Import-Csv
- Function authoring: param() blocks, [CmdletBinding()], Mandatory parameters, begin/process/end pipeline support
- Module management: Get-Module, Import-Module, Install-Module from PSGallery, New-ModuleManifest
- PowerShell Remoting: Enter-PSSession, Invoke-Command (multi-server), New-PSSession, Copy-Item -ToSession
- Object manipulation: [PSCustomObject], Get-Member, Format-Table, ConvertTo-Json/ConvertFrom-Json, Add-Member
Frequently Asked Questions
What is PowerShell and how is it different from Command Prompt (cmd)?
PowerShell is an object-oriented shell and scripting language built on .NET. Unlike cmd which passes text between commands, PowerShell passes structured .NET objects through its pipeline, enabling powerful data manipulation without string parsing. PowerShell 7+ is cross-platform (Windows, Linux, macOS) while Windows PowerShell 5.1 is Windows-only.
What is the $_ variable in PowerShell?
$_ (also written as $PSItem) represents the current object in the pipeline. It is used in script blocks passed to Where-Object, ForEach-Object, and similar cmdlets. For example: `Get-Process | Where-Object { $_.CPU -gt 100 }` filters processes where the CPU property exceeds 100.
How do I filter objects in the PowerShell pipeline?
Use Where-Object with a script block: `Get-Service | Where-Object { $_.Status -eq "Running" }`. For PowerShell 3.0+, you can use the simplified syntax: `Get-Service | Where-Object Status -eq "Running"`. For performance on large datasets, filter early in the pipeline using cmdlet-specific parameters like -Filter.
How do I create a custom object in PowerShell?
Use [PSCustomObject] with a hashtable literal: `$obj = [PSCustomObject]@{ Name = "Server01"; IP = "192.168.1.1"; Status = "Online" }`. You can add properties later with Add-Member: `$obj | Add-Member -MemberType NoteProperty -Name "Region" -Value "KR"`. Use $obj | Format-Table to display the object as a table.
How do I run PowerShell commands on multiple remote servers?
Use Invoke-Command with -ComputerName: `Invoke-Command -ComputerName Server01, Server02 -ScriptBlock { Get-Service | Where-Object { $_.Status -eq "Running" } }`. For repeated operations on the same server, create a persistent session with New-PSSession and reuse it with -Session to avoid the overhead of creating new connections each time.
How do I install PowerShell modules from PSGallery?
Run `Install-Module -Name ModuleName -Scope CurrentUser -Force`. Common modules include Az (Azure), AWS.Tools.* (AWS), SqlServer, and ImportExcel. Use `Find-Module -Name "Az*"` to search for modules. Set the execution policy if needed: `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`.
How do I read and write files in PowerShell?
Read with Get-Content: `Get-Content -Path "file.txt"` or `Get-Content -Path "app.log" -Tail 50` for the last 50 lines. Write with Set-Content (overwrite) or Add-Content (append). For structured data, use Import-Csv/Export-Csv for CSV files and ConvertFrom-Json/ConvertTo-Json for JSON data.
What is the difference between [CmdletBinding()] and a basic function?
[CmdletBinding()] transforms a function into an "advanced function" that supports common parameters like -Verbose, -Debug, -ErrorAction, and -WhatIf. It also enables parameter validation attributes like [Parameter(Mandatory=$true)], [ValidateSet()], and [ValidateRange()]. Use it for any function intended for reuse or module distribution.