Loop break continue script

Welcome Forums General PowerShell Q&A Loop break continue script

This topic contains 2 replies, has 2 voices, and was last updated by

bin
 
Participant
1 year, 4 months ago.

  • Author
    Posts
  • #74044
    bin

    Participant
    Points: 0
    Rank: Member

    Hello

    I try to create a script with validation input, and condition: if folder exist enter yes to continue the scipt, or quit to return the powershell host command, else if the folder does not exist continue the script.
    the break and continue have the same result it continue the script
    # the scipt
    $folderexist=test-path c:\history
    if ($Folderexist) {
    do{
    $input=read-host "folder exist if you want enter Y(y) to continue or Q(q) to quit"

    if ($input -match "Q"){
    write-host "you choice to quit the script to powershell host"
    break
    }elseif ($input -match "Y"){write-host "continue script"
    }
    }
    until ($input -match "y|q")

    }else{write-host "continue script"}

    #continue script
    .....thé script continuez wish 100 lines

  • #74048

    Participant
    Points: 59
    Rank: Member
    $myPath = 'c:\history'
    
    if (Test-Path $myPath) {
        $Looping = $true
        do {
            $myInput = (Read-Host "Folder ($myPath) exists, hit Y/y to continue or Q/q to stop").ToUpper()
            switch ($myInput) {
                Y { $Looping = $false }
                Q { $Looping = $false }
                Default { [console]::beep(300,300) }
            }
        } while ($Looping)
        if ($myInput -eq 'Y') {
            #region Script branch when folder exists AND Y/y is selected
            "Folder ($myPath) exists, and (Y) is selected"
    
            #endregion
        } else {
            #region Script branch when folder exists AND Q/q is selected
            "Folder ($myPath) exists, and (Q) is selected"
    
            #endregion    
        }
    } else {
        #region Script branch when folder does NOT exist
        "Folder ($myPath) does not exist"
    
        #endregion
    }
    
    • #74093
      bin

      Participant
      Points: 0
      Rank: Member

      Gréât......Tanks

The topic ‘Loop break continue script’ is closed to new replies.