Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
2  
Make sure to accept the answer when its a good one ;-) Keeps the community in good holiday spirits!! –  Mike Dec 7 '12 at 20:16
add comment

1 Answer

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
share|improve this answer
    
Wow, that simple, never thought of trying that. Thanks a bunch –  Jens Svendsen Dec 7 '12 at 8:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.