Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6626607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:54:43+00:00 2026-05-25T21:54:43+00:00

Compare the three scripts below: Sample 1 $a = GPS | Where {$_.ProcessName -Match

  • 0

Compare the three scripts below:

Sample 1

$a = GPS | Where {$_.ProcessName -Match 'AcroRd32'}
$a
$a.Count

If ($a.Count -Eq 0)
{
    Echo "Adobe Reader is Off"
}
Else
{
    Echo "Adobe Reader is On"
}

# If Adobe Reader is not running, how come 0 (zero) is not returned?
# This is prettier, should I use it?  Or does it slow down performance?


Sample 2

$a = GPS AcroRd32
$a
$a.Count

If ($a.Count -Eq 0)
{
    Echo "Adobe Reader is Off"
}
Else
{
    Echo "Adobe Reader is On"
}

# If Adobe Reader is not running, how come 0 (zero) is not returned?
# This is uglier, but it doesn't have to pipe any output, so does it have any performance gains?


Sample 3

GPS AcroRd32 | Measure | Select -Expand Count

# 0 (zero) is returned, but with an ugly Error


I guess part of my problem is that I’m treating PowerShell like it’s VBS; writing code in this manner/style would usually yield me an integer value of zero and not throw any errors (if Adobe Reader was off, of course). What’s the correct PowerShell way of checking that an instance of a program is not running? The performance questions in the comments are secondary to the “PowerShell Way” question.

P.S. To be honest, the Error Message returned by the 3rd Sample wouldn’t break anything, it’s just ugly, so it’s not beyond practical use, so I guess the real problem is that I’m just a sucker for aesthetics =^D

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:54:44+00:00Added an answer on May 25, 2026 at 9:54 pm

    This is a common PowerShell gotcha. A command can return:

    • Nothing ~ null (does not have the property Count, getting it either gets null or fails)
    • A single object (it may have its own property Count property, the most confusing case — can return anything; or may not have it, then getting Count gets null or fails)
    • 2+ object array which has the property Count.

    The solution is simple. When you really need the count of returned objects use the @() operator. The result is always an array which has the property Count.

    # this is always an array
    $result = @(<command returning something or nothing>)
    
    # this is always a number:
    $result.Count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the below script. two arrays with only three values.when i compare these two
I have to compare three dates in linq query (datetime a < datetime b
In my Stata do scripts, I often have to compare dates which may be
I have designed a stored procedure usign Sql Server 2005 below to compare 3
Is there any diff tool for Lotus Notes which allows to compare scripts, design
Is there an easy way to compare the file tree of an old git
Are there any tools to effectively compare two XML schema's? I have seen some
Is there a way in JavaScript to compare values from one array and see
Is there a better way to compare a NSNumber with a fixed value, it
Is there a program to compare one folder and all subfolders to another folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.