420-1Q1-AA Help

Solutions

Solution 1 : Affichage de Texte

Write-Output "Bonjour, PowerShell !"

Solution 2 : Variables et Calculs

$a = 5 $b = 10 $somme = $a + $b Write-Output $somme

Solution 3 : Boucle For

for ($i = 1; $i -le 10; $i++) { Write-Output $i }

Solution 4 : Création de Fichier

"Ceci est un fichier PowerShell" | Out-File -FilePath "exemple.txt"

Solution 5 : Liste des Processus

Get-Process | Format-Table

Solution 6 : Fonction Simple

function Afficher-Salutation { param ([string]$nom) Write-Output "Bonjour $nom !" } Afficher-Salutation -nom "Jean"

Solution 7 : Vérification d'Existence de Fichier

if (Test-Path "exemple.txt") { Write-Output "Le fichier existe." } else { Write-Output "Le fichier n'existe pas." }

Solution 8 : Boucle While

$i = 1 while ($i -le 5) { Write-Output $i $i++ }

Solution 9 : Table de Multiplication

for ($i = 1; $i -le 10; $i++) { Write-Output "7 x $i = $(7 * $i)" }

Solution 10 : Lecture de Fichier

Get-Content -Path "exemple.txt" | ForEach-Object { Write-Output $_ }
Last modified: 16 October 2024