![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Yield to the OS Hi If I have a while loop that simply holds execution until a command has completed how do I stop it frying the processor? What I am actually doing is mapping a network drive and I want to ensure this has finished before continuing e.g. $net = $(New-Object -Com WScript.Network) ForEach ($hst in $hstLst) { $pingStatus = gwmi Win32_PingStatus -Filter "Address='$Hst'" If($pingStatus.StatusCode -eq 0) { $path = "\\" + $hst + "\C$\Temp" $path $net.MapNetworkDrive("Z:", $path) While(![System.IO.Directory]::Exists("Z:")){} write-host -ForegroundColor GREEN $hst $(get-acl z .access$net.RemoveNetworkDrive("Z:", $true) While([System.IO.Directory]::Exists("Z:")){} } Else { write-host -ForegroundColor RED $Hst" - UNAVAILABLE" } } How can I yield to the OS during the while loop? Thanks for any help you can offer |
My System Specs![]() |
| | #2 (permalink) |
| Guest | RE: Yield to the OS start-sleep ? -- greetings dreeschkind "Andy Webster" wrote: > Hi > > If I have a while loop that simply holds execution until a command has > completed how do I stop it frying the processor? > > What I am actually doing is mapping a network drive and I want to ensure > this has finished before continuing e.g. > > $net = $(New-Object -Com WScript.Network) > ForEach ($hst in $hstLst) > { > $pingStatus = gwmi Win32_PingStatus -Filter "Address='$Hst'" > If($pingStatus.StatusCode -eq 0) > { > $path = "\\" + $hst + "\C$\Temp" > $path > $net.MapNetworkDrive("Z:", $path) > While(![System.IO.Directory]::Exists("Z:")){} > write-host -ForegroundColor GREEN $hst > $(get-acl z .access> $net.RemoveNetworkDrive("Z:", $true) > While([System.IO.Directory]::Exists("Z:")){} > } > Else > { > write-host -ForegroundColor RED $Hst" - UNAVAILABLE" > } > } > > How can I yield to the OS during the while loop? > > Thanks for any help you can offer |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Yield to the OS Try a start-sleep. Like While(![System.IO.Directory]::Exists("Z:")){start-sleep 5} "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message news:88FEF1D7-8356-47F2-B995-F7CDF6F877CD@microsoft.com... > Hi > > If I have a while loop that simply holds execution until a command has > completed how do I stop it frying the processor? > > What I am actually doing is mapping a network drive and I want to ensure > this has finished before continuing e.g. > > $net = $(New-Object -Com WScript.Network) > ForEach ($hst in $hstLst) > { > $pingStatus = gwmi Win32_PingStatus -Filter "Address='$Hst'" > If($pingStatus.StatusCode -eq 0) > { > $path = "\\" + $hst + "\C$\Temp" > $path > $net.MapNetworkDrive("Z:", $path) > While(![System.IO.Directory]::Exists("Z:")){} > write-host -ForegroundColor GREEN $hst > $(get-acl z .access> $net.RemoveNetworkDrive("Z:", $true) > While([System.IO.Directory]::Exists("Z:")){} > } > Else > { > write-host -ForegroundColor RED $Hst" - UNAVAILABLE" > } > } > > How can I yield to the OS during the while loop? > > Thanks for any help you can offer |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Yield to the OS Thanks guys, easy when you know how !! "Brandon Shell" wrote: > Try a start-sleep. > > Like > While(![System.IO.Directory]::Exists("Z:")){start-sleep 5} > > "Andy Webster" <AndyWebster@discussions.microsoft.com> wrote in message > news:88FEF1D7-8356-47F2-B995-F7CDF6F877CD@microsoft.com... > > Hi > > > > If I have a while loop that simply holds execution until a command has > > completed how do I stop it frying the processor? > > > > What I am actually doing is mapping a network drive and I want to ensure > > this has finished before continuing e.g. > > > > $net = $(New-Object -Com WScript.Network) > > ForEach ($hst in $hstLst) > > { > > $pingStatus = gwmi Win32_PingStatus -Filter "Address='$Hst'" > > If($pingStatus.StatusCode -eq 0) > > { > > $path = "\\" + $hst + "\C$\Temp" > > $path > > $net.MapNetworkDrive("Z:", $path) > > While(![System.IO.Directory]::Exists("Z:")){} > > write-host -ForegroundColor GREEN $hst > > $(get-acl z .access> > $net.RemoveNetworkDrive("Z:", $true) > > While([System.IO.Directory]::Exists("Z:")){} > > } > > Else > > { > > write-host -ForegroundColor RED $Hst" - UNAVAILABLE" > > } > > } > > > > How can I yield to the OS during the while loop? > > > > Thanks for any help you can offer > > |
My System Specs![]() |