420-1Q1-AA Help

PowerShell Cmdlets — Cheat Sheet

How to read

  • CmdletExplanation


    Example

Files & Folders

  • Get-ChildItem (ls/dir) — Liste fichiers/dossiers.


    Get-ChildItem C:\Data -Recurse -Force

  • Set-Location (cd) — Change le répertoire courant.


    Set-Location C:\Logs

  • Get-Item / Set-Item — Lit/modifie un item (fichier, clé registre…).


    Get-Item .\report.txt

  • Copy-Item (cp) — Copie fichiers/dossiers.


    Copy-Item .\data.csv D:\Archive\

  • Move-Item (mv) — Déplace/renomme.


    Move-Item .\old.txt .\old.bak

  • New-Item — Crée fichier/dossier.


    New-Item -ItemType Directory C:\Temp\Out

  • Remove-Item (rm) — Supprime fichiers/dossiers.


    Remove-Item .\*.log -Force

  • Test-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 -Wait

  • Set-Content — Écrit (écrase).


    "Hello" | Set-Content .\hello.txt -Encoding UTF8

  • Add-Content — Ajoute.


    "Line+" | Add-Content .\log.txt

  • Clear-Content — Vide un fichier.


    Clear-Content .\temp.txt

  • Select-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, WS

  • Stop-Process — Termine un processus.


    Stop-Process -Name notepad -Force

  • Start-Process — Lance un exécutable.


    Start-Process notepad.exe -ArgumentList .\file.txt

  • Get-Service — Liste services.


    Get-Service | Where-Object Status -eq Running

  • Start/Stop/Restart-Service — Gère un service.


    Restart-Service -Name Spooler

System & Session

  • Get-Command — Trouve commandes.


    Get-Command -Verb Get

  • Get-Help — Aide + exemples.


    Get-Help Get-Process -Online

  • Get-Module / Import-Module — Modules.


    Get-Module -ListAvailable

  • Get-ComputerInfo — Infos système (PS7+).


    Get-ComputerInfo | Select-Object OsName, OsVersion

  • Get-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 10

  • Where-Object — Filtrer (scriptblock).


    ... | Where-Object { $_.CPU -gt 10 }

  • Sort-Object — Trier.


    ... | Sort-Object CPU -Descending

  • Measure-Object — Compter, somme, avg.


    ... | Measure-Object -Property Length -Sum

  • Group-Object — Grouper par propriété.


    ... | Group-Object Extension | Sort Count -Desc

  • ForEach-Object — Itération pipeline.


    ... | ForEach-Object { $_.Name.ToUpper() }

Formatting & Export

  • Format-Table/Format-List — Mise en forme console.


    ... | Format-Table -AutoSize

  • Out-File — Écrit vers fichier.


    ... | Out-File .\out.txt -Encoding UTF8

  • Export-Csv / Import-Csv — Échange tabulaire.


    Get-Service | Export-Csv .\svc.csv -NoTypeInformation

  • ConvertTo-Json / ConvertFrom-Json — JSON.


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

  • ConvertTo-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 4

  • Test-NetConnection — Ports/route DNS.


    Test-NetConnection github.com -Port 443

  • Invoke-WebRequest (iwr) — HTTP client (fichiers, scraping).


    Invoke-WebRequest https://example.com -OutFile index.html

  • Invoke-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 $true

  • Get-LocalGroup / Add-LocalGroupMember — Groupes locaux.


    Add-LocalGroupMember -Group Administrators -Member Alice

  • Get-Acl / Set-Acl — ACL fichiers.


    $acl = Get-Acl .\data; Set-Acl -Path .\data -AclObject $acl

  • Get-Credential — Invite des identifiants.


    $cred = Get-Credential

Packages & Environment

  • Get-Package / Find-Package / Install-Package — PackageManagement.


    Find-Package 7zip | Install-Package -Force

  • Get-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\Microsoft

  • Get-ItemProperty / Set-ItemProperty — Valeurs registre.


    Get-ItemProperty 'HKCU:\Software\MyApp'

Archives & Compression

  • Compress-Archive — Zip.


    Compress-Archive -Path .\logs\* -DestinationPath .\logs.zip

  • Expand-Archive — Unzip.


    Expand-Archive .\logs.zip -DestinationPath .\out

Scripting Essentials

  • Variables$x = 1

  • If / Elseif ($x -gt 0) { "pos" } else { "neg" }

  • Loopsforeach, for, while

  • Functions

    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,OwningProcess

  • CSV to JSON


    Import-Csv .\in.csv | ConvertTo-Json | Out-File .\out.json

  • HTML Report for Services


    Get-Service | ConvertTo-Html | Out-File .\services.html

Last modified: 07 October 2025