PowerShell introduction: install, pipeline, commands
PowerShell is a cross-platform shell and scripting language built on .NET. Where Bash and cmd.exe pass text between commands, PowerShell passes .NET objects: Get-Process returns process objects with properties such as Name, Id and WorkingSet, and the next command in the pipeline can filter or sort on those properties without parsing columns of text. That makes it strong for automation on Windows (Active Directory, IIS, Azure, Microsoft 365) and useful everywhere else.
There are two products with similar names. Windows PowerShell 5.1 ships with Windows, runs on .NET Framework and gets only security fixes. PowerShell 7 (the pwsh executable) is the current, open-source, cross-platform version. In November 2026 the current release is PowerShell 7.6 (LTS, built on .NET 10, supported until November 2028); PowerShell 7.4 and 7.5 reached end of support on November 10, 2026. Everything on this page targets PowerShell 7.6.
The samples are commands to type at a pwsh prompt. PowerShell was not available in the environment used to write this page, so they were not run here; each command and parameter was checked against the PowerShell 7.6 reference on Microsoft Learn. Output shown is what the documentation describes.
Topics on this page
Section titled “Topics on this page”| Topic | What it covers |
|---|---|
| Install and run | Installing PowerShell 7.6 on each platform and checking the version. |
| Objects and the pipeline | Verb-Noun cmdlets, variables, arrays and hash tables, and filtering, sorting and selecting objects. |
| Symbols and operators | What $_, @(), $(), &, |, >, && and the other symbols mean. |
| Everyday commands | Navigating, creating files and folders, opening things, transcripts and one-liners. |
| Getting help | Get-Help, Get-Command and Get-Member, the three commands that teach you the rest. |
For scripts, functions, parameters and error handling, continue with PowerShell scripting basics.
Install and run
Section titled “Install and run”On Windows, Windows PowerShell 5.1 is already installed, but install PowerShell 7 alongside it; they do not conflict. On macOS use Homebrew. On Linux, first register Microsoft’s package repository for your distribution (the Microsoft Learn install page gives the exact steps for each one), then install the powershell package. Start it with pwsh.
# Windowswinget install --id Microsoft.PowerShell --source winget
# macOSbrew install --cask powershell
# Ubuntu, after registering packages.microsoft.com for your releasesudo apt-get updatesudo apt-get install -y powershell
# Any platform: check what you are running$PSVersionTable.PSVersion[System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescriptionOn PowerShell 7.6 the first command reports major version 7 and minor version 6, and the second reports .NET 10.0.x. Visual Studio Code with the PowerShell extension is the recommended editor; the Windows PowerShell ISE does not support PowerShell 7.
Pitfalls:
powershellversuspwsh.powershell.exestarts Windows PowerShell 5.1;pwshstarts PowerShell 7. Scripts and scheduled tasks often call the wrong one.apt install powershellfails on a fresh machine. The package is not in Ubuntu’s own repositories; register Microsoft’s repository first.
Objects and the pipeline
Section titled “Objects and the pipeline”Commands are named Verb-Noun: Get-Process, Set-Location, New-Item, Remove-Item, Start-Service, Invoke-RestMethod. The verbs come from an approved list (Get-Verb shows it), so once you know Get-ChildItem you can guess Get-Content and Get-Service. Variables start with $ and hold any .NET object; @() builds an array and @{} a hash table.
The pipe | passes objects to the next command. Where-Object filters, Sort-Object sorts, Select-Object picks properties or the first N items, Group-Object groups and Measure-Object counts or sums. Inside a script block, $_ (or $PSItem) is the current object. Formatting cmdlets such as Format-Table belong at the very end, because they turn objects into display text.
# Variables, arrays and hash tables$customer = "Dana Reyes"$orders = @(1001, 1002, 1003)$order = @{ Id = 1001; Customer = $customer; Total = 128.48 }"Order $($order.Id) for $customer totals $($order.Total)" # Order 1001 for Dana Reyes totals 128.48$orders.Count # 3
# The five largest log files under the current folderGet-ChildItem -Path . -Filter *.log -Recurse | Sort-Object -Property Length -Descending | Select-Object -First 5 -Property Name, Length
# Processes using more than 200 MB, biggest firstGet-Process | Where-Object WorkingSet -gt 200MB | Sort-Object WorkingSet -Descending
# Count error lines per day in an application logGet-Content .\ordersportal.log | Select-String -Pattern 'ERROR' | Group-Object { $_.Line.Substring(0, 10) } | Select-Object Name, Count
# Transform each item1..5 | ForEach-Object { $_ * 2 } # 2 4 6 8 10 (one per line)200MB is a numeric literal with a size suffix (KB, MB, GB, TB, PB). Where-Object WorkingSet -gt 200MB is the short form of Where-Object { $_.WorkingSet -gt 200MB }.
Pitfalls:
- Formatting too early.
Get-Process | Format-Table | Sort-Object Namesorts formatting records, not processes. Filter and sort first, format last. - Filtering on the right.
Get-ChildItem -Recurse | Where-Object Extension -eq '.log'enumerates every file first;-Filter *.loglets the file system do the work. - Comparison operators are words.
-eq,-gt,-likeand-match, not==or>;>is redirection (next section).
Symbols and operators
Section titled “Symbols and operators”PowerShell packs a lot of meaning into punctuation. The table lists the symbols you will meet in almost every script.
| Symbol | Meaning | Example |
|---|---|---|
. and .. |
Current and parent folder | Set-Location .. |
~ |
Your home folder | Set-Location ~ |
$ |
Variable | $total = 42 |
$_ or $PSItem |
Current pipeline object | Where-Object { $_.Total -gt 100 } |
| |
Pipeline: pass objects to the next command | Get-Service | Sort-Object Status |
@( ) |
Array (always an array, even with one item) | @(Get-ChildItem *.log).Count |
@{ } |
Hash table | @{ Name = 'KB-101'; Qty = 2 } |
$( ) |
Subexpression inside a string | "Total: $($order.Total)" |
& |
Call operator: run a command held in a string or a script block | & "C:\Tools\backup.exe" -full |
. (dot-source) |
Run a script in the current scope so its functions stay defined | . .\helpers.ps1 |
:: |
Static .NET member | [Math]::Round(2.567, 2) |
.. (range) |
Integer range | 1..5 |
` |
Escape character and line continuation | "Tab:`tEnd" |
; |
Statement separator | cd ~; Get-ChildItem |
# and <# #> |
Line comment and block comment | # TODO |
> and >> |
Redirect output to a file (overwrite, append), same as Out-File |
Get-Process > procs.txt |
2> and *> |
Redirect the error stream, or all streams | .\build.ps1 2> errors.txt |
&& and || |
Run the next command only if the previous succeeded or failed (PowerShell 7) | dotnet build && dotnet test |
? : |
Ternary operator (PowerShell 7) | $isProd ? 'prod' : 'dev' |
?? and ??= |
Null-coalescing and null-coalescing assignment (PowerShell 7) | $region ?? 'westeurope' |
Strings in double quotes expand variables and escapes ("Hello $name"); strings in single quotes are literal ('Hello $name'). Use single quotes unless you need expansion.
Pitfalls:
- Backtick continuation is fragile. A space after the backtick breaks the line. Prefer splatting (
$params = @{...}; Invoke-RestMethod @params) or break after a pipe|, which continues automatically. $()in strings."Total: $order.Total"prints the hash table followed by.Total; property access needs"$($order.Total)".
Everyday commands
Section titled “Everyday commands”These are the commands that cover most interactive work. Many have short aliases (cd, ii, gci), but some aliases exist only on Windows: on Linux and macOS, ls, cp, mv, rm, cat, ps, kill, sort and start are not PowerShell aliases, so the native tool runs instead. Use full cmdlet names in scripts.
# NavigateSet-Location "C:\Projects\OrdersPortal" # alias: cdPush-Location .\src; Pop-Location # go somewhere and come back
# Create a folder and a file (-ItemType decides which)New-Item -ItemType Directory -Path .\logsNew-Item -ItemType File -Path .\logs\today.log"Started import" | Add-Content -Path .\logs\today.log
# Copy, move, delete (preview a destructive command with -WhatIf)Copy-Item .\appsettings.json .\appsettings.backup.jsonMove-Item .\old-report.csv .\archive\Remove-Item .\temp -Recurse -WhatIf
# Open a folder, file or URL with its default applicationInvoke-Item . # alias: ii; opens Explorer or FinderInvoke-Item .\reports\orders.xlsxStart-Process "http://localhost:5123/" # opens the default browser
# Record everything in this session to a fileStart-Transcript -Path .\logs\session.txtStop-Transcript
# Useful one-linersGet-ChildItem -Recurse -File | Where-Object LastWriteTime -gt (Get-Date).AddDays(-7)Get-Content .\ordersportal.log -Tail 20 -Wait # follow a log, like tail -fGet-ChildItem Env: # environment variables$env:ASPNETCORE_ENVIRONMENT = 'Development' # set one for this session[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('hello')) # aGVsbG8=Pitfalls:
New-Itemwithout-ItemType. On the file system it creates a file; pass-ItemType Directoryfor a folder.Remove-Item -Recursehas no recycle bin. Run it with-WhatIffirst, and use-Confirmin scripts that delete user data.
Getting help
Section titled “Getting help”Three commands teach you everything else. Get-Command finds commands by name, verb or noun. Get-Help shows syntax, parameter descriptions and examples; run Update-Help once (as administrator on Windows) to download the full help files, or add -Online to open the Microsoft Learn page. Get-Member lists the properties and methods of whatever object you pipe into it, which is how you discover what to filter on.
Get-Command -Verb Get -Noun *Service*Get-Help Get-ChildItem -ExamplesGet-Help Invoke-RestMethod -OnlineGet-Process | Get-Member -MemberType PropertyGet-Alias -Definition Get-ChildItem # which aliases point at a cmdletPitfalls:
- Guessing property names. Pipe to
Get-Member(orSelect-Object -First 1 -Property *) instead of guessing; display columns often have different names from the real properties.
Interview questions
Section titled “Interview questions”What is the main difference between the PowerShell pipeline and a Bash pipeline? Bash pipes bytes of text, so each command must parse the previous command’s output. PowerShell pipes .NET objects, so the next command reads typed properties directly and output formatting never breaks the next step.
What is the difference between Windows PowerShell 5.1 and PowerShell 7?
5.1 is built into Windows on .NET Framework and only receives security fixes. PowerShell 7 is open source, cross-platform, built on modern .NET (7.6 on .NET 10), installs side by side and adds operators such as &&, ||, ?? and the ternary operator.
Why should scripts avoid aliases such as ls or %?
They hurt readability and some do not exist on every platform: ls, cp, rm and start are not aliases on Linux and macOS, so the script silently runs a native tool with different parameters.
How do you find out what properties an object has?
Pipe it to Get-Member, or to Select-Object -Property * to see values.
Senior scenario: an operations team runs dozens of ad hoc PowerShell one-liners against production servers. How would you make this safer?
Turn the common tasks into a versioned module of advanced functions with [CmdletBinding(SupportsShouldProcess)] so they honor -WhatIf and -Confirm, validate parameters, and log with Start-Transcript or structured logs. Run them through PowerShell remoting or a pipeline with least-privilege accounts (Just Enough Administration endpoints restrict which commands an operator can run), sign scripts and set an execution policy that requires signatures, and review changes in source control.
Related pages
Section titled “Related pages”- PowerShell scripting basics
- What is .NET?: the runtime PowerShell 7 is built on.