PowerShell Cmdlets — Cheat Sheet
How to read
Cmdlet — Explanation
Example
Files & Folders
Get-ChildItem (ls/dir) — Liste fichiers/dossiers.
Get-ChildItem C:\Data -Recurse -ForceSet-Location (cd) — Change le répertoire courant.
Set-Location C:\LogsGet-Item / Set-Item — Lit/modifie un item (fichier, clé registre…).
Get-Item .\report.txtCopy-Item (cp) — Copie fichiers/dossiers.
Copy-Item .\data.csv D:\Archive\Move-Item (mv) — Déplace/renomme.
Move-Item .\old.txt .\old.bakNew-Item — Crée fichier/dossier.
New-Item -ItemType Directory C:\Temp\OutRemove-Item (rm) — Supprime fichiers/dossiers.
Remove-Item .\*.log -ForceTest-Path — Vérifie l’existence.
if (Test-Path C:\Temp) { "OK" }Resolve-Path — Chemin absolu canonique.
Resolve-Path .\..\Config
File Content
Get-Content (cat/type) — Lit du texte.
Get-Content .\notes.txt -Tail 20 -WaitSet-Content — Écrit (écrase).
"Hello" | Set-Content .\hello.txt -Encoding UTF8Add-Content — Ajoute.
"Line+" | Add-Content .\log.txtClear-Content — Vide un fichier.
Clear-Content .\temp.txtSelect-String (grep) — Recherche texte/regex.
Select-String -Path .\*.ps1 -Pattern '\bTODO\b'
Processes & Services
Get-Process — Liste processus.
Get-Process | Sort-Object WS -Desc | Select-Object -First 5 Name, Id, WSStop-Process — Termine un processus.
Stop-Process -Name notepad -ForceStart-Process — Lance un exécutable.
Start-Process notepad.exe -ArgumentList .\file.txtGet-Service — Liste services.
Get-Service | Where-Object Status -eq RunningStart/Stop/Restart-Service — Gère un service.
Restart-Service -Name Spooler
System & Session
Get-Command — Trouve commandes.
Get-Command -Verb GetGet-Help — Aide + exemples.
Get-Help Get-Process -OnlineGet-Module / Import-Module — Modules.
Get-Module -ListAvailableGet-ComputerInfo — Infos système (PS7+).
Get-ComputerInfo | Select-Object OsName, OsVersionGet-Date / Set-Date — Date/Heure.
Get-Date -Format "yyyy-MM-dd HH:mm:ss"Get-History / Invoke-History — Historique.
Get-History | Select-Object -Last 10
Objects & Pipeline
Select-Object — Colonnes & top-n.
... | Select-Object Name, Id -First 10Where-Object — Filtrer (scriptblock).
... | Where-Object { $_.CPU -gt 10 }Sort-Object — Trier.
... | Sort-Object CPU -DescendingMeasure-Object — Compter, somme, avg.
... | Measure-Object -Property Length -SumGroup-Object — Grouper par propriété.
... | Group-Object Extension | Sort Count -DescForEach-Object — Itération pipeline.
... | ForEach-Object { $_.Name.ToUpper() }
Formatting & Export
Format-Table/Format-List — Mise en forme console.
... | Format-Table -AutoSizeOut-File — Écrit vers fichier.
... | Out-File .\out.txt -Encoding UTF8Export-Csv / Import-Csv — Échange tabulaire.
Get-Service | Export-Csv .\svc.csv -NoTypeInformationConvertTo-Json / ConvertFrom-Json — JSON.
Get-Process | Select Name,Id | ConvertTo-Json -Depth 3ConvertTo-Html — Rapport HTML.
Get-Process | Select Name,WS | ConvertTo-Html | Out-File .\proc.html
Networking (de base)
Test-Connection (ping) — Ping ICMP.
Test-Connection 1.1.1.1 -Count 4Test-NetConnection — Ports/route DNS.
Test-NetConnection github.com -Port 443Invoke-WebRequest (iwr) — HTTP client (fichiers, scraping).
Invoke-WebRequest https://example.com -OutFile index.htmlInvoke-RestMethod (irm) — API JSON.
Invoke-RestMethod https://api.github.com/repos/PowerShell/PowerShell
Security & Identity
Get-LocalUser / New-LocalUser — Comptes locaux.
Get-LocalUser | Where Enabled -eq $trueGet-LocalGroup / Add-LocalGroupMember — Groupes locaux.
Add-LocalGroupMember -Group Administrators -Member AliceGet-Acl / Set-Acl — ACL fichiers.
$acl = Get-Acl .\data; Set-Acl -Path .\data -AclObject $aclGet-Credential — Invite des identifiants.
$cred = Get-Credential
Packages & Environment
Get-Package / Find-Package / Install-Package — PackageManagement.
Find-Package 7zip | Install-Package -ForceGet-ChildItem Env: — Variables d’env.
Get-ChildItem Env:[Environment]::SetEnvironmentVariable() — .NET API.
[Environment]::SetEnvironmentVariable("FOO","bar","User")
Jobs & Scheduled Tasks
Start-Job / Get-Job / Receive-Job — Jobs en arrière-plan.
Start-Job -ScriptBlock { Get-Process }Register-ScheduledTask — Tâche planifiée (module ScheduledTasks).
Register-ScheduledTask -Action (New-ScheduledTaskAction -Execute 'pwsh' -Argument '-File C:\task.ps1') -Trigger (New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(5)) -TaskName 'RunOnce'
PowerShell Remoting (WinRM/SSH)
Enter-PSSession — Session interactive distance.
Enter-PSSession -ComputerName srv01 -Credential (Get-Credential)Invoke-Command — Exécute à distance.
Invoke-Command -ComputerName srv01 -ScriptBlock { Get-Service }New-PSSession / Remove-PSSession — Gère sessions persistantes.
$s = New-PSSession srv01; Invoke-Command -Session $s -ScriptBlock { hostname }
Registry
Get-Item / Set-Item / New-Item sous
HKLM:/HKCU:.Get-ChildItem HKLM:\Software\MicrosoftGet-ItemProperty / Set-ItemProperty — Valeurs registre.
Get-ItemProperty 'HKCU:\Software\MyApp'
Archives & Compression
Compress-Archive — Zip.
Compress-Archive -Path .\logs\* -DestinationPath .\logs.zipExpand-Archive — Unzip.
Expand-Archive .\logs.zip -DestinationPath .\out
Scripting Essentials
Variables —
$x = 1If / Else —
if ($x -gt 0) { "pos" } else { "neg" }Loops —
foreach,for,whileFunctions—
function Get-TopMemory { param([int]$Top = 5) Get-Process | Sort WS -Desc | Select -First $Top Name,Id,WS }Try/Catch—
try { Get-Content .\x.txt -ErrorAction Stop } catch { Write-Error "Lecture impossible: $_" }
Quick Patterns (recettes)
Top 10 large files
Get-ChildItem -Recurse | Where Length -gt 0 | Sort Length -Desc | Select -First 10 FullName, @{n='MB';e={[math]::Round($_.Length/1MB,2)}}Find listening TCP ports (Win 10/11)
Get-NetTCPConnection | Where State -eq Listen | Select LocalAddress,LocalPort,OwningProcessCSV to JSON
Import-Csv .\in.csv | ConvertTo-Json | Out-File .\out.jsonHTML Report for Services
Get-Service | ConvertTo-Html | Out-File .\services.html