Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.


Go Back   Vista Forums > Misc Newsgroups > PowerShell

RB

Vista - Process count wrong when only one process matches criteria

Reply
 
10-05-2007   #1
malverson26


 
 

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
10-05-2007   #2
Kiron


 
 

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
10-05-2007   #3
malverson26


 
 

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
10-06-2007   #4
Keith Hill [MVP]


 
 

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
Reply

RB


Thread Tools


Similar Threads for: Process count wrong when only one process matches criteria
Thread Forum
Failover Guest Cluster -- 'The process cannot access the file becauseit is being used by another process.' Virtual Server
Process Handle Count Charting PowerShell
get-process & stop-process by owner PowerShell
File count wrong........... Vista file management
Bug? Shouldn't Stop-Process automatically match Id if object is a process? PowerShell


Vista Forums 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 Ltd