Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Yield to the OS

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 07-10-2007   #1 (permalink)
Andy Webster
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 SpecsSystem Spec
Old 07-10-2007   #2 (permalink)
dreeschkind
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 SpecsSystem Spec
Old 07-10-2007   #3 (permalink)
Brandon Shell
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 SpecsSystem Spec
Old 07-11-2007   #4 (permalink)
Andy Webster
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 SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes




Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008