3

I am trying to use Get-AQDUser to get a summed list of users per country. So far a have this

$Country = Read-Host "Please Enter the country of which you want to see users "
Get-QADUser -ObjectAttributes @{co="$Country"} | ft displayname, co -auto

and this lists the user names perfectly, but not summed. To get them summed i added the following to above

| Measure-Object

This gives me the number of users, but it counts 4 more users than there is. If I search for users in ADUC, it gives me the correct number. I also tried with the .Count parameter, but this also gives me 4 more users, than there actually are. And i am searching from the root of our AD.

Any idea, why |measure-object always gives me 4 users too many?

1
  • 2
    Make sure to accept the answer when its a good one ;-) Keeps the community in good holiday spirits!!
    – Mike
    Dec 7, 2012 at 20:16

1 Answer 1

2

Measure-Object measures whatever is piped into it, in your case, the output of Format-Table. This means Measure-Object will measure the table, including the headers, separators, etc., as well as the values.

Example:

Get-ADUser jscott | Measure-Object
Count    : 1
...

Get-ADUser jscott | Format-Table | Measure-Object
Count    : 5
...

Exactly four extra. You should probably just skip the Format-Table until you want to display the output values on-screen, after you've counted them. Using your example, the following should return the correct number of users:

Get-QADUser -ObjectAttributes @{co="$Country"} | Measure-Object
1
  • Wow, that simple, never thought of trying that. Thanks a bunch Dec 7, 2012 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .