PowerShell cheatsheet

Doorzoekbare lijst met essentiële PowerShell-cmdlets voor bestanden, processen, services, de pipeline en remoting, voor PowerShell 7 en 5.1.

Draait in je browser · er wordt niets verstuurdNieuw

44 commando’s

Get-Help <cmdlet> -FullShow the full help page for a cmdlet, including parameters and examples.

Without -Full you get a short summary. Add -Online to open the up-to-date web page instead, or -Examples for just the example section.

Voorbeeld

Get-Help Get-ChildItem -Examples

Opties

-OnlineOpen the latest documentation in your browser.
-ExamplesShow only usage examples.
-Parameter <name>Show help for one parameter.
Get-Command *process*Find cmdlets, functions and aliases by (partial) name.

Wildcards work on both sides. Use -Noun or -Verb to search by one part of a Verb-Noun name.

Voorbeeld

Get-Command -Verb Get -Noun Service

Opties

-Verb <verb>Only commands with this verb, for example Get, Set, New.
-Noun <noun>Only commands with this noun.
-Module <name>Only commands from one module.
<expression> | Get-MemberList the properties and methods of whatever object(s) came through the pipeline.

Everything in PowerShell is an object, not text, so Get-Member is the main way to discover what you can do with a result before writing the rest of a script.

Voorbeeld

Get-Process | Get-Member -MemberType Property

Opties

-MemberType PropertyOnly properties, not methods.
-StaticStatic members of the type instead of the instance.
Update-HelpDownload the latest help files for installed modules.

Help files are not included by default on a fresh install. Run this once (as Administrator) so Get-Help and -Online have real content.

Let op: Requires internet access and, the first time, an elevated session.
Get-ExecutionPolicy -ListShow the script execution policy for each scope.

Controls whether .ps1 scripts are allowed to run at all. Change it with Set-ExecutionPolicy, most safely at the CurrentUser scope.

Voorbeeld

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Opties

RestrictedNo scripts at all (common default on Windows PowerShell 5.1).
RemoteSignedLocal scripts run freely; downloaded scripts need a trusted signature.
BypassNo restriction and no warnings.
Let op: This is a convenience control, not a security boundary: it only affects double-clicking or running .ps1 files directly, not every way code can execute.
$PROFILEShow the path to your current PowerShell profile script.

A profile script runs automatically at the start of every session, a common place for aliases, functions and module imports. PowerShell 7 and Windows PowerShell 5.1 use separate profile files, so settings do not carry over automatically.

Voorbeeld

notepad $PROFILE
Get-ChildItem [path]List files and folders. Aliased as ls, dir and gci.

Works on the file system, but also on other PowerShell drives such as the registry (HKLM:\) or environment variables (Env:\).

Voorbeeld

Get-ChildItem -Recurse -Filter *.log | Select-Object -First 10

Opties

-RecurseInclude subfolders.
-Filter <pattern>Fast, provider-level wildcard filter.
-FileOnly files.
-DirectoryOnly folders.
-ForceInclude hidden and system items.
Set-Location <path>Change the current directory. Aliased as cd and sl.

Also works on non-filesystem drives, which is how you “cd” into the registry.

Voorbeeld

Set-Location -Path HKLM:\SOFTWARE
Copy-Item <source> <destination>Copy a file or folder.

Opties

-RecurseRequired to copy a folder with its contents.
-ForceOverwrite an existing destination and copy read-only or hidden items.
Move-Item <source> <destination>Move or rename a file or folder.

Moving to a new name in the same folder is how you rename something.

Remove-Item <path>Delete a file or folder.

Opties

-RecurseRequired to delete a non-empty folder.
-ForceDelete hidden, read-only or system items without prompting.
-WhatIfPreview what would be deleted, without deleting it.
Let op: There is no recycle bin here: Remove-Item deletes permanently. Run with -WhatIf first when the path is built from a variable or wildcard.
New-Item -Path <path> -ItemType <type>Create a new file, folder, or other item.

Voorbeeld

New-Item -Path .\notes.txt -ItemType File

Opties

-ItemType DirectoryCreate a folder.
-ItemType FileCreate an empty file.
-Value <text>Initial content for a new file.
Test-Path <path>Check whether a file, folder or registry key exists. Returns True or False.

The usual guard before reading a file or creating one only if it is missing.

Voorbeeld

if (-not (Test-Path .\out)) { New-Item -ItemType Directory .\out }
Get-Content <path>Read a text file, one line per pipeline object. Aliased as cat, gc and type.

Voorbeeld

Get-Content .\app.log -Tail 20 -Wait

Opties

-Tail <n>Only the last n lines.
-WaitKeep the file open and show new lines as they are written, like tail -f.
-RawRead the whole file as one string instead of a line array.
Set-Content <path> -Value <text>Write text to a file, replacing its contents.

Add-Content appends instead of replacing. Out-File is similar but designed to receive pipeline output rather than a -Value string.

Opties

-Encoding UTF8Set the text encoding explicitly, since the default differs between Windows PowerShell 5.1 (UTF-8 with BOM) and PowerShell 7 (UTF-8 without BOM).
<expression> | Select-Object <properties>Pick specific properties, or the first/last N objects.

Voorbeeld

Get-Process | Select-Object Name, CPU -First 5

Opties

-First <n>Only the first n objects.
-Last <n>Only the last n objects.
-ExpandProperty <name>Return the raw values of one property instead of objects.
-UniqueRemove duplicate rows after the selection.
<expression> | Where-Object { <condition> }Filter pipeline objects by a condition. Aliased as where and ?.

$_ refers to the current object. A simplified syntax also works for simple comparisons: Where-Object CPU -gt 10.

Voorbeeld

Get-Process | Where-Object { $_.CPU -gt 10 }
<expression> | Sort-Object <property>Sort pipeline objects by one or more properties.

Voorbeeld

Get-ChildItem | Sort-Object Length -Descending

Opties

-DescendingLargest or last first.
-UniqueRemove duplicates after sorting.
<expression> | ForEach-Object { <script> }Run a script block once per pipeline object. Aliased as % and foreach.

Different from the foreach statement (foreach ($x in $list) {}): ForEach-Object processes one item at a time as it arrives in the pipeline, which uses much less memory for large collections.

Voorbeeld

Get-ChildItem *.txt | ForEach-Object { Rename-Item $_ ($_.Name + ".bak") }
<expression> | Group-Object <property>Group pipeline objects by a property and count each group.

Voorbeeld

Get-Process | Group-Object Company | Sort-Object Count -Descending
<expression> | Measure-Object <property>Count objects, or sum/average/min/max a numeric property.

Voorbeeld

Get-ChildItem *.log | Measure-Object -Property Length -Sum

Opties

-SumTotal of the property.
-AverageAverage value.
-MaximumLargest value.
-MinimumSmallest value.
<expression> | Format-Table -AutoSizeFormat objects as a table in the console.

Only for display: the output becomes text, so do not pipe it into another cmdlet that expects objects. Format-List shows one property per line instead, better for objects with many properties.

Opties

-AutoSizeSize columns to fit the content.
-WrapWrap long values instead of truncating them.
<expression> | ConvertTo-JsonSerialize objects to a JSON string.

Voorbeeld

Get-Process | Select-Object Name, Id | ConvertTo-Json -Depth 3

Opties

-Depth <n>How many levels of nested objects to include (default 2, often too shallow for complex objects).
<expression> | Export-Csv <path> -NoTypeInformationWrite objects to a CSV file.

-NoTypeInformation drops the #TYPE header line. On PowerShell 7 it is the default and the switch is unnecessary, but harmless to include for scripts shared with Windows PowerShell 5.1.

Voorbeeld

Get-Process | Export-Csv processes.csv -NoTypeInformation
Get-ProcessList running processes.

Voorbeeld

Get-Process -Name chrome | Sort-Object CPU -Descending

Opties

-Name <name>Filter by process name.
-Id <pid>Get one process by its process ID.
Stop-Process -Id <pid>End a running process.

Opties

-Name <name>Stop by process name instead of ID (stops every matching process).
-ForceStop a process that would otherwise prompt for confirmation.
Let op: Unsaved work in that process is lost. Prefer closing the application normally when possible.
Get-ServiceList Windows services and their status. Not available on Linux or macOS.

Voorbeeld

Get-Service -Name wuauserv

Opties

-Name <name>Filter by service name (wildcards allowed).
-DisplayName <name>Filter by the friendly display name.
Restart-Service -Name <name>Restart a Windows service.

Start-Service and Stop-Service do the same for just starting or stopping. Requires an elevated session for most system services.

Get-WinEvent -LogName System -MaxEvents 50Read entries from a Windows event log.

Get-WinEvent replaces the older Get-EventLog, which only reads classic logs and is not available in PowerShell 7 on non-Windows systems (and is deprecated even on Windows).

Voorbeeld

Get-WinEvent -FilterHashtable @{ LogName = "Security"; Id = 4625 } -MaxEvents 20

Opties

-FilterHashtableEfficient server-side filtering by log name, event ID, level or time.
-MaxEvents <n>Limit how many entries are returned.
Restart-ComputerRestart the computer, locally or on a remote one.

Opties

-ComputerName <name>Restart a remote computer (needs permission and remoting enabled).
-ForceRestart even if users are logged on, without waiting.
Let op: Closes everything running on that computer. Save work and warn other users on shared or remote machines first.
Get-HotFixList installed Windows updates.

Windows-only. For driver and feature update history, Windows Update's own history view is more complete than Get-HotFix.

$name = <value>Create or update a variable.

Variable names are not case-sensitive. No declaration keyword is needed; the first assignment creates it.

Voorbeeld

$count = 5
$name = "web-server-01"
"text $variable text"Insert a variable into a string. Only works inside double quotes, not single quotes.

For a property or expression, wrap it: "Count is $($list.Count)". Single-quoted strings are literal and never interpolate.

Voorbeeld

"Server $name has $count cores"
if (<condition>) { } elseif (<condition>) { } else { }Conditional branching.

Comparison uses operators like -eq, -ne, -gt, -lt, -like and -match, not ==, !=, >, <, which PowerShell parses differently (as redirection in some contexts).

Voorbeeld

if ($count -gt 10) { "many" } elseif ($count -gt 0) { "some" } else { "none" }
foreach ($item in $collection) { }Loop over a collection, loading it into memory first.

For very large or streamed input, ForEach-Object in a pipeline is usually more memory-efficient.

Voorbeeld

foreach ($file in Get-ChildItem *.log) { Write-Host $file.Name }
function Verb-Noun { param($x) ... }Define a reusable function.

Community convention is an approved Verb-Noun name (see Get-Verb) so your function behaves like a built-in cmdlet and is easy to discover.

Voorbeeld

function Get-FileAge {
  param([string]$Path)
  (Get-Date) - (Get-Item $Path).LastWriteTime
}
try { } catch { } finally { }Handle errors that would otherwise stop the script.

Only catches terminating errors. Many cmdlets write non-terminating errors instead; add -ErrorAction Stop to force a cmdlet call to throw one that try/catch can catch.

Voorbeeld

try {
  Get-Item nonexistent.txt -ErrorAction Stop
} catch {
  Write-Warning $_.Exception.Message
}
-eq -ne -gt -ge -lt -leEquality and comparison operators.

Case-insensitive by default for strings. Prefix with c for case-sensitive (-ceq) or i to be explicit about case-insensitive (-ieq).

Opties

-eq / -neEqual / not equal.
-gt / -geGreater than / greater than or equal.
-lt / -leLess than / less than or equal.
-like / -notlikeWildcard match with * and ?.
-match / -notmatchRegular expression match.
Get-InstalledModuleList modules installed from the PowerShell Gallery (via PowerShellGet).

Get-Module -ListAvailable shows every module PowerShell can find, including built-in ones; Get-InstalledModule is scoped to what you installed yourself.

Install-Module -Name <name> -Scope CurrentUserDownload and install a module from the PowerShell Gallery.

Opties

-Scope CurrentUserInstall for your user only, no elevation needed.
-Scope AllUsersInstall machine-wide; needs an elevated session.
-ForceReinstall or install without confirmation prompts.
Let op: Modules from the Gallery are community-published. Check the publisher and download count before installing something you depend on for production use.
Import-Module <name>Load a module into the current session.

Most modules auto-load the first time one of their commands is used, so this is mainly needed for modules that do not support auto-loading, or to load a specific version.

Invoke-Command -ComputerName <name> -ScriptBlock { }Run a script block on a remote computer over WS-Management (PowerShell Remoting).

Requires PowerShell Remoting to be enabled on the target (Enable-PSRemoting) and, usually, administrative rights there. On the target machine the script runs under Windows PowerShell 5.1 unless the target also has PowerShell 7 remoting configured.

Voorbeeld

Invoke-Command -ComputerName srv01 -ScriptBlock { Get-Service -Name wuauserv }

Opties

-Credential <cred>Run as a different user on the remote computer.
-ComputerName <names>One or more target computers, run in parallel.
Enter-PSSession -ComputerName <name>Open an interactive remote session, similar to SSH.

Exit-PSSession or exit returns to the local session. For running the same command on many computers at once, Invoke-Command is usually a better fit than looping Enter-PSSession.

Get-CredentialPrompt for a username and password, returned as a PSCredential object.

Pass the result to a cmdlet's -Credential parameter. The password is stored as a SecureString in memory, not as plain text, but it is still decrypted when the target cmdlet uses it.

Voorbeeld

$cred = Get-Credential
Invoke-Command -ComputerName srv01 -Credential $cred -ScriptBlock { whoami }

De omschrijvingen in dit naslagwerk zijn voorlopig in het Engels.

Uitleg

Zoek of filter op groep en kopieer een cmdlet met één klik. Open een cmdlet voor uitleg, een voorbeeld, de belangrijkste parameters en waarschuwingen waar het schade kan aanrichten. Commando’s werken op zowel Windows PowerShell 5.1 als PowerShell 7, tenzij anders vermeld.

🔒 Je invoer blijft in je browser en wordt nergens naartoe gestuurd.

Veelgestelde vragen

Moet ik Windows PowerShell 5.1 of PowerShell 7 leren?

Voor nieuwe scripts: PowerShell 7. Die wordt actief ontwikkeld en draait op Windows, Linux en macOS. Windows PowerShell 5.1 wordt nog steeds met Windows meegeleverd, en sommige Windows-only modules (zoals veel ActiveDirectory-cmdlets) laden alleen daar.

Wat nu?

Ook handig

  • Git cheatsheetDoorzoekbare lijst met de handigste Git-commando’s voor setup, branches, remotes, wijzigingen ongedaan maken en geschiedenis bekijken.
  • Linux-commando’s cheatsheetDoorzoekbare lijst met essentiële Linux-commando’s voor bestanden, rechten, tekst, processen, services, netwerk en gebruikers.
  • Windows Event-ID opzoekenZoek veelvoorkomende Windows Event-ID’s op: aanmelden, accountwijzigingen, services, Kerberos, RDP en PowerShell. Handig bij storingen en audits.
  • Windows security baseline checkerPlak een secedit-export om wachtwoordbeleid, auditinstellingen en registerbeveiliging te controleren tegen bekende baseline-aanbevelingen.

Een probleem gevonden of een suggestie? Laat het ons weten