User prompts in PowerShell

This first example is a simple Yes / No…..

#region select search
$Correct = "N"
while($Correct -ne "Y"){

    $SelectedSearch = Read-Host -Prompt "Enter the name of the search you wish to action"
    $Correct = Read-Host -Prompt "Is this the correct Search '$SelectedSearch' (y/n)"
#endregion select search

This second example nests another confirmation…..

#region hard or soft
$Correct = "N"
while($Correct -ne "Y"){

    $Action = "X"
    $Actions = "h", "s"
    while($Actions -notcontains $Action){

        $Action = Read-Host -Prompt "Hard Delete or Soft Delete (h/s)"
    if($Action -eq "s"){$ActionDesc = "Soft Delete"}
    elseif($Action -eq "h"){$ActionDesc = "Hard Delete"}
    $Correct = Read-Host -Prompt "Is this the correct action '$ActionDesc' (y/n)"
#endregion hard or soft

Leave a Reply

Your email address will not be published. Required fields are marked *

five × 5 =