From 8c3a86dd7fe97355b77b2dde7a926b2e3667c3eb Mon Sep 17 00:00:00 2001 From: Mickael Asseline Date: Sat, 8 May 2021 15:29:48 +0000 Subject: [PATCH] docs: update Scripting/Powershell --- Scripting/Powershell.html | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Scripting/Powershell.html b/Scripting/Powershell.html index 16d9513..fb7fe1c 100644 --- a/Scripting/Powershell.html +++ b/Scripting/Powershell.html @@ -2,7 +2,7 @@ title: Powershell description: published: true -date: 2021-05-08T15:28:57.451Z +date: 2021-05-08T15:29:46.673Z tags: editor: ckeditor dateCreated: 2021-05-08T14:42:07.092Z @@ -15,9 +15,8 @@ dateCreated: 2021-05-08T14:42:07.092Z

Principe de fonctionnement

Nous avons besoin de déclarer une variable qui va servir en quelque sorte de bouton “allumé” ou “éteins” : $continue = $true

Avec cette variable j'utilise une boucle pour permettre de laisser en permanence l'affichage : 

-
while (true)
-{
-<le menu avec des write-host>
+
while (true){
+	<le menu avec des write-host>
 }

Puis une seconde variable pour stocker mon choix avec $choix = read-host “faire un choix”

Suivant l'état de ce choix le script sortira de la boucle while et cela provoquera soit une action du script soit une sortie du script avec switch ($choix).

@@ -25,19 +24,20 @@ dateCreated: 2021-05-08T14:42:07.092Z

 

Exemple

$continue = $true
-while (continue)
-{
-write-host “----------------------MON TITRE -----------------------”
-write-host “1. mon action 1”
-write-host "2. mon action2"
-write-host "x. exit"
-write-host"-------------------------------------------------------------------"
-$choix = read-host “faire un choix”
-switch ($choix)
-{
-1{commande de mon action 1}
-2{commande de mon action 2} 
-‘x’ {$continue= $false}
-default {Write-Host "Choix invalide"-ForegroundColor Red}
-}
+while (continue){ + write-host “----------------------MON TITRE -----------------------” + write-host “1. mon action 1” + write-host "2. mon action2" + write-host "x. exit" + write-host"-------------------------------------------------------------------" + $choix = read-host “faire un choix” + switch ($choix){ + {commande de mon action 1} + {commande de mon action 2} + ‘x’ {$continue= $false} + default {Write-Host "Choix invalide"-ForegroundColor Red} + } +} + +