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

Process count wrong when only one process matches criteria

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 10-05-2007   #1 (permalink)
malverson26
Guest


 

Process count wrong when only one process matches criteria

Trying to use get-process to determine when one job is finished to start
another one
$abc | % {
([wmiClass]"\\localhost\ROOT\CIMV2:win32_process").Create("xyz");
while ((get-process xyz).count -gt 0 {start-sleep 60}
}

However when there is only one process that matches the count property does
not return 1 and the comparison operators don't return the expected results.
See below for examples.

When two calc processes are running
PS C:\> (get-process calc).count -gt 0
True
PS C:\> (get-process calc).count
2
PS C:\>

When one calc proecess is running
PS C:\> (get-process calc).count -gt 0
False
PS C:\> (get-process calc).count
PS C:\>



My System SpecsSystem Spec
Old 10-05-2007   #2 (permalink)
Kiron
Guest


 

Re: Process count wrong when only one process matches criteria

It's the way PowerShell handles, or mishandles, scalar objects. Wrap the get-process statement in array notation '@()':

$abc | % {
([wmiClass]"\\localhost\ROOT\CIMV2:win32_process").Create("xyz");
while (@(get-process xyz).count -gt 0 {start-sleep 60}
}

--
Kiron
My System SpecsSystem Spec
Old 10-05-2007   #3 (permalink)
malverson26
Guest


 

Re: Process count wrong when only one process matches criteria

Thank you that got it.

"Kiron" wrote:
Quote:

> It's the way PowerShell handles, or mishandles, scalar objects. Wrap the
> get-process statement in array notation '@()':
>
> $abc | % {
> ([wmiClass]"\\localhost\ROOT\CIMV2:win32_process").Create("xyz");
> while (@(get-process xyz).count -gt 0 {start-sleep 60}
> }
>
> --
> Kiron
>
My System SpecsSystem Spec
Old 10-06-2007   #4 (permalink)
Keith Hill [MVP]
Guest


 

Re: Process count wrong when only one process matches criteria

"malverson26" <malverson26@xxxxxx> wrote in message
news:4F55A117-5C0D-4FCB-8D9E-2F52A650D6AE@xxxxxx
Quote:

> Thank you that got it.
>
There are some other nuances concerning scalars vs collections vs empty set
(no output). I wrote a blog post on this subject you might find useful:

http://keithhill.spaces.live.com/blo...3A97!816.entry

--
Keith

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
get-process & stop-process by owner Andrew Conrad PowerShell 3 03-03-2007 04:11 PM
File count wrong........... =?Utf-8?B?V2Fyd2ljayBXZWJi?= Vista file management 0 09-29-2006 07:47 AM
Process dwm.exe rarno Vista installation & setup 0 06-23-2006 08:37 AM
Process dwm.exe rarno Vista installation & setup 0 06-23-2006 08:36 AM
Bug? Shouldn't Stop-Process automatically match Id if object is a process? Alex K. Angelopoulos [MVP] PowerShell 3 06-21-2006 05:35 AM


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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51