Aide-mémoire PowerShell
Liste consultable des applets de commande PowerShell essentielles pour fichiers, processus, services, pipeline et remoting, pour PowerShell 7 et 5.1.
S’exécute dans votre navigateur · rien n’est envoyéNouveau
44 commandes
Get-Help <cmdlet> -FullShow the full help page for a cmdlet, including parameters and examples.
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.
Exemple
Get-Help Get-ChildItem -Examples
Options
-Online | Open the latest documentation in your browser. |
|---|---|
-Examples | Show only usage examples. |
-Parameter <name> | Show help for one parameter. |
Get-Command *process*Find cmdlets, functions and aliases by (partial) name.
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.
Exemple
Get-Command -Verb Get -Noun Service
Options
-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.
<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.
Exemple
Get-Process | Get-Member -MemberType Property
Options
-MemberType Property | Only properties, not methods. |
|---|---|
-Static | Static members of the type instead of the instance. |
Update-HelpDownload the latest help files for installed modules.
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.
Get-ExecutionPolicy -ListShow the script execution policy for each scope.
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.
Exemple
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
Options
Restricted | No scripts at all (common default on Windows PowerShell 5.1). |
|---|---|
RemoteSigned | Local scripts run freely; downloaded scripts need a trusted signature. |
Bypass | No restriction and no warnings. |
$PROFILEShow the path to your current PowerShell profile script.
$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.
Exemple
notepad $PROFILE
Get-ChildItem [path]List files and folders. Aliased as ls, dir and gci.
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:\).
Exemple
Get-ChildItem -Recurse -Filter *.log | Select-Object -First 10
Options
-Recurse | Include subfolders. |
|---|---|
-Filter <pattern> | Fast, provider-level wildcard filter. |
-File | Only files. |
-Directory | Only folders. |
-Force | Include hidden and system items. |
Set-Location <path>Change the current directory. Aliased as cd and sl.
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.
Exemple
Set-Location -Path HKLM:\SOFTWARE
Copy-Item <source> <destination>Copy a file or folder.
Copy-Item <source> <destination>Copy a file or folder.Options
-Recurse | Required to copy a folder with its contents. |
|---|---|
-Force | Overwrite an existing destination and copy read-only or hidden items. |
Move-Item <source> <destination>Move or rename a file or folder.
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.
Remove-Item <path>Delete a file or folder.Options
-Recurse | Required to delete a non-empty folder. |
|---|---|
-Force | Delete hidden, read-only or system items without prompting. |
-WhatIf | Preview what would be deleted, without deleting it. |
New-Item -Path <path> -ItemType <type>Create a new file, folder, or other item.
New-Item -Path <path> -ItemType <type>Create a new file, folder, or other item.Exemple
New-Item -Path .\notes.txt -ItemType File
Options
-ItemType Directory | Create a folder. |
|---|---|
-ItemType File | Create 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.
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.
Exemple
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.
Get-Content <path>Read a text file, one line per pipeline object. Aliased as cat, gc and type.Exemple
Get-Content .\app.log -Tail 20 -Wait
Options
-Tail <n> | Only the last n lines. |
|---|---|
-Wait | Keep the file open and show new lines as they are written, like tail -f. |
-Raw | Read the whole file as one string instead of a line array. |
Set-Content <path> -Value <text>Write text to a file, replacing its contents.
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.
Options
-Encoding UTF8 | Set 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.
<expression> | Select-Object <properties>Pick specific properties, or the first/last N objects.Exemple
Get-Process | Select-Object Name, CPU -First 5
Options
-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. |
-Unique | Remove duplicate rows after the selection. |
<expression> | Where-Object { <condition> }Filter pipeline objects by a condition. Aliased as where and ?.
<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.
Exemple
Get-Process | Where-Object { $_.CPU -gt 10 }<expression> | Sort-Object <property>Sort pipeline objects by one or more properties.
<expression> | Sort-Object <property>Sort pipeline objects by one or more properties.Exemple
Get-ChildItem | Sort-Object Length -Descending
Options
-Descending | Largest or last first. |
|---|---|
-Unique | Remove duplicates after sorting. |
<expression> | ForEach-Object { <script> }Run a script block once per pipeline object. Aliased as % and foreach.
<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.
Exemple
Get-ChildItem *.txt | ForEach-Object { Rename-Item $_ ($_.Name + ".bak") }<expression> | Group-Object <property>Group pipeline objects by a property and count each group.
<expression> | Group-Object <property>Group pipeline objects by a property and count each group.Exemple
Get-Process | Group-Object Company | Sort-Object Count -Descending
<expression> | Measure-Object <property>Count objects, or sum/average/min/max a numeric property.
<expression> | Measure-Object <property>Count objects, or sum/average/min/max a numeric property.Exemple
Get-ChildItem *.log | Measure-Object -Property Length -Sum
Options
-Sum | Total of the property. |
|---|---|
-Average | Average value. |
-Maximum | Largest value. |
-Minimum | Smallest value. |
<expression> | Format-Table -AutoSizeFormat objects as a table in the console.
<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.
Options
-AutoSize | Size columns to fit the content. |
|---|---|
-Wrap | Wrap long values instead of truncating them. |
<expression> | ConvertTo-JsonSerialize objects to a JSON string.
<expression> | ConvertTo-JsonSerialize objects to a JSON string.Exemple
Get-Process | Select-Object Name, Id | ConvertTo-Json -Depth 3
Options
-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.
<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.
Exemple
Get-Process | Export-Csv processes.csv -NoTypeInformation
Get-ProcessList running processes.
Get-ProcessList running processes.Exemple
Get-Process -Name chrome | Sort-Object CPU -Descending
Options
-Name <name> | Filter by process name. |
|---|---|
-Id <pid> | Get one process by its process ID. |
Stop-Process -Id <pid>End a running process.
Stop-Process -Id <pid>End a running process.Options
-Name <name> | Stop by process name instead of ID (stops every matching process). |
|---|---|
-Force | Stop a process that would otherwise prompt for confirmation. |
Get-ServiceList Windows services and their status. Not available on Linux or macOS.
Get-ServiceList Windows services and their status. Not available on Linux or macOS.Exemple
Get-Service -Name wuauserv
Options
-Name <name> | Filter by service name (wildcards allowed). |
|---|---|
-DisplayName <name> | Filter by the friendly display name. |
Restart-Service -Name <name>Restart a Windows service.
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 -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).
Exemple
Get-WinEvent -FilterHashtable @{ LogName = "Security"; Id = 4625 } -MaxEvents 20Options
-FilterHashtable | Efficient 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.
Restart-ComputerRestart the computer, locally or on a remote one.Options
-ComputerName <name> | Restart a remote computer (needs permission and remoting enabled). |
|---|---|
-Force | Restart even if users are logged on, without waiting. |
Get-HotFixList installed Windows updates.
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.
$name = <value>Create or update a variable.Variable names are not case-sensitive. No declaration keyword is needed; the first assignment creates it.
Exemple
$count = 5 $name = "web-server-01"
"text $variable text"Insert a variable into a string. Only works inside double quotes, not single quotes.
"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.
Exemple
"Server $name has $count cores"
if (<condition>) { } elseif (<condition>) { } else { }Conditional branching.
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).
Exemple
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.
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.
Exemple
foreach ($file in Get-ChildItem *.log) { Write-Host $file.Name }function Verb-Noun { param($x) ... }Define a reusable function.
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.
Exemple
function Get-FileAge {
param([string]$Path)
(Get-Date) - (Get-Item $Path).LastWriteTime
}try { } catch { } finally { }Handle errors that would otherwise stop the script.
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.
Exemple
try {
Get-Item nonexistent.txt -ErrorAction Stop
} catch {
Write-Warning $_.Exception.Message
}-eq -ne -gt -ge -lt -leEquality and comparison operators.
-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).
Options
-eq / -ne | Equal / not equal. |
|---|---|
-gt / -ge | Greater than / greater than or equal. |
-lt / -le | Less than / less than or equal. |
-like / -notlike | Wildcard match with * and ?. |
-match / -notmatch | Regular expression match. |
Get-InstalledModuleList modules installed from the PowerShell Gallery (via PowerShellGet).
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.
Install-Module -Name <name> -Scope CurrentUserDownload and install a module from the PowerShell Gallery.Options
-Scope CurrentUser | Install for your user only, no elevation needed. |
|---|---|
-Scope AllUsers | Install machine-wide; needs an elevated session. |
-Force | Reinstall or install without confirmation prompts. |
Import-Module <name>Load a module into the current session.
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).
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.
Exemple
Invoke-Command -ComputerName srv01 -ScriptBlock { Get-Service -Name wuauserv }Options
-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.
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.
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.
Exemple
$cred = Get-Credential
Invoke-Command -ComputerName srv01 -Credential $cred -ScriptBlock { whoami }Les descriptions de cette référence sont pour l’instant en anglais.
Explication
Recherchez ou filtrez par groupe et copiez une applet de commande en un clic. Ouvrez-en une pour voir ce qu’elle fait, un exemple, ses principaux paramètres et des avertissements là où elle peut faire des dégâts. Les commandes fonctionnent sur Windows PowerShell 5.1 et PowerShell 7, sauf mention contraire.
🔒 Votre saisie reste dans votre navigateur et n’est envoyée nulle part.
Questions fréquentes
Faut-il apprendre Windows PowerShell 5.1 ou PowerShell 7 ?
Pour de nouveaux scripts, PowerShell 7 : il est activement développé et fonctionne sur Windows, Linux et macOS. Windows PowerShell 5.1 reste fourni avec Windows, et certains modules propres à Windows (comme de nombreuses applets ActiveDirectory) ne se chargent que là.
Et ensuite ?
Un problème ou une suggestion ? Dites-le-nous