Powershell: Fix My Loop Logic -


i trying logic straightened out loop need continue prompt user enter valid unc path. have set test path , output console path invalid. but, after that, moves prompt choice. want instead, ask user enter valid path before moving on next step. here loop:

do{     write-host ""                         $pathprompt  = write-host "please enter path file/folder:" -foregroundcolor cyan;     $path        = read-host;      $test        = test-path $path      if($test -eq $false){         write-host "error! invalid path!" -foregroundcolor red     } }until($test -eq $true){     write-host ""     write-host "getting acl on"$path -foregroundcolor green     get-ntfsaccess -path $path } 

what missing or not doing right here?

sounds want reuse validation test. put in function reuse:

function get-validpath {     {         write-host "`r`nplease enter path file/folder:" -foregroundcolor cyan         $path = read-host         $test = test-path $path          if ($test -eq $false) {             write-host "error! invalid path!" -foregroundcolor red         }     } until ($test -eq $true)     $path } $validatedpath1 = get-validpath write-host "`r`ngetting acl on $validatedpath1" -foregroundcolor green get-ntfsaccess -path $validatedpath1 $validatedpath2 = get-validpath 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -