Basics
Auteur : Gautier RAYEROUX | Date : 2026-04-15 00:00:00
🔹 Déclaration de variables
Section titled “🔹 Déclaration de variables”$age = 25$nom = "Gautier"$estConnecte = $true$pi = 3.14$ville = "Angers" # typage dynamique🔹 Structures de contrôle
Section titled “🔹 Structures de contrôle”Condition
Section titled “Condition”if ($age -gt 18) { Write-Output "Majeur"}else { Write-Output "Mineur"}Switch
Section titled “Switch”switch ($jour) { "lundi" { Write-Output "Début de semaine" } default { Write-Output "Autre jour" }}Boucles
Section titled “Boucles”# forfor ($i = 0; $i -lt 5; $i++) { Write-Output $i}
# while$i = 0while ($i -lt 5) { Write-Output $i $i++}
# foreach$fruits = @("pomme", "banane", "orange")foreach ($fruit in $fruits) { Write-Output $fruit}🔹 Fonctions
Section titled “🔹 Fonctions”function Dire-Bonjour { param($nom) Write-Output "Bonjour $nom"}
function Addition { param( [int]$a, [int]$b ) return ($a + $b)}🔹 Objets & Classes
Section titled “🔹 Objets & Classes”class Personne { [string]$Nom [int]$Age
[void]SePresenter() { Write-Output "Je m'appelle $($this.Nom) et j'ai $($this.Age) ans." }}
# Utilisation$p = [Personne]::new()$p.Nom = "Gautier"$p.Age = 26$p.SePresenter()🔹 Listes et Tableaux
Section titled “🔹 Listes et Tableaux”# Tableau$notes = @(10, 15, 20)
# Liste dynamique (ArrayList)$couleurs = New-Object System.Collections.ArrayList$couleurs.Add("Rouge") | Out-Null$couleurs.Add("Bleu") | Out-Null🔹 Null safety
Section titled “🔹 Null safety”$nom = $nullif ($null -ne $nom) { Write-Output $nom.Length}🔹 Try / Catch (gestion d’erreurs)
Section titled “🔹 Try / Catch (gestion d’erreurs)”try { [int]::Parse("abc")}catch { Write-Output "Erreur : $($_.Exception.Message)"}🔹 Script PowerShell (structure minimale)
Section titled “🔹 Script PowerShell (structure minimale)”Write-Output "Hello World!"
# Paramètres possiblesparam( [string]$Utilisateur, [switch]$VerboseMode)
Write-Output "Utilisateur : $Utilisateur"