Do Whle issue


wanting check if folder exists, if not, keep looping sayings not there yet; if , move on. why not working me?  have misunderstanding how conditional logic of while loop works.  i'm sure there plenty of easier ways this, , i'm game see suggestions, great if explain why logic below isn't sound? runs through 1 iteration, doesn't loop.

many thanks,

        $stoploop = $false          {                 if (test-path c:\path)                     {                         write-host 'folder exists';start-sleep -seconds 2                         $stoploop = $true                     }                 else                     {                         write-host 'folder doesnt exist';start-sleep -seconds 2                     }             }         while ($stoploop = $false)



hi,

this construct use:

$found = $false  {      if (test-path c:\path) {          write-host 'path found!' -foregroundcolor green         $found = $true      } else {          write-host 'not found yet.' -foregroundcolor red         start-sleep -seconds 2      }  } until ($found)


edit: answer initial question though, you're not using correct test in while statement. you'd need use while ($stoploop -eq $false). using = sets value $false, doesn't testing.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file