Author Posts

July 2, 2017 at 9:44 am

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

July 2, 2017 at 10:40 am

$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
}

July 2, 2017 at 6:18 pm

Gréât......Tanks