miroir de
https://github.com/PAPAMICA/Wiki-Tech.io.git
synchronisé 2025-03-06 12:30:58 +01:00
docs: update Scripting/Powershell
Cette révision appartient à :
Parent
eebf7e53a8
révision
e580bc42a1
1 fichiers modifiés avec 29 ajouts et 1 suppressions
|
@ -2,7 +2,7 @@
|
||||||
title: Powershell
|
title: Powershell
|
||||||
description:
|
description:
|
||||||
published: true
|
published: true
|
||||||
date: 2021-05-08T14:50:23.559Z
|
date: 2021-05-08T15:17:37.703Z
|
||||||
tags:
|
tags:
|
||||||
editor: ckeditor
|
editor: ckeditor
|
||||||
dateCreated: 2021-05-08T14:42:07.092Z
|
dateCreated: 2021-05-08T14:42:07.092Z
|
||||||
|
@ -12,4 +12,32 @@ dateCreated: 2021-05-08T14:42:07.092Z
|
||||||
<p>Pour faire un menu sous powershell, </p>
|
<p>Pour faire un menu sous powershell, </p>
|
||||||
<figure class="image"><img src="/capture.png"></figure>
|
<figure class="image"><img src="/capture.png"></figure>
|
||||||
<p> </p>
|
<p> </p>
|
||||||
|
<h2>principe de fonctionnement</h2>
|
||||||
|
<p>il va falloir déclarer une variable qui va servir en quelque sorte de bouton…allumé ou éteinds</p>
|
||||||
|
<p><code>$continue = $true</code></p>
|
||||||
|
<p>avec cette variable j'utilise une boucle pour permettre de laisser en permanence l'affichage</p>
|
||||||
|
<p><code>while (true)</code></p>
|
||||||
|
<p>{</p>
|
||||||
|
<p>le menu avec des write-host</p>
|
||||||
|
<p>}</p>
|
||||||
|
<p>puis il va me falloir une autre variable pour stocker mon choix avec<code> $choix = read-host “faire un choix”</code></p>
|
||||||
|
<p>suivant l'état de ce choix je sortirai de la boucle while et cela provoquera soit une action du script soit une sortie du script avec switch ($choix)</p>
|
||||||
|
<p>pour sortir du script si je fait le choix ‘x’ je passe la variable <code>$continue à false </code> ce qui aura pour effet d'arrêter la boucle while</p>
|
||||||
<p> </p>
|
<p> </p>
|
||||||
|
<h2>aperçu d'une construction de menu</h2>
|
||||||
|
<p>$continue = $true</p>
|
||||||
|
<p>while (continue)</p>
|
||||||
|
<p>{</p>
|
||||||
|
<p>write-host “----------------------MON TITRE -----------------------”</p>
|
||||||
|
<p>write-host “1. mon action 1”</p>
|
||||||
|
<p>write-host "2. mon action2"</p>
|
||||||
|
<p>write-host"-------------------------------------------------------------------"</p>
|
||||||
|
<p>$choix = read-host “faire un choix”</p>
|
||||||
|
<p>switch ($choix)</p>
|
||||||
|
<p>{</p>
|
||||||
|
<ol>
|
||||||
|
<li>{commande de mon action 1}</li>
|
||||||
|
<li>{commande de mon action 2} </li>
|
||||||
|
</ol>
|
||||||
|
<p>‘x’ {$continue= false}</p>
|
||||||
|
<p>default {{Write-Host "Choix invalide"-ForegroundColor Red}</p><p>}</p><p> </p>
|
||||||
|
|
Chargement…
Ajouter une table
Référencer dans un nouveau ticket