Adding a filter to a property

Hi Folks,

i have wrote this line here to get a count of all users from an OU
(Get-ADUser -Filter "objectcategory -eq 'user'" -SearchBase "OU=microsoft=com").count

Open in new window


however i'm also trying to add a filter where it would only select active users... this line here i know will pick this specifici object but I don't know how to tell it just to pick the ones that are active
(Get-ADUser -Filter "objectcategory -eq 'user'" -SearchBase "ou=microsoft=com" -properties * | select-object enabled).count

Open in new window


does anybody have any idea on how to accompllish it?

thanks for looking
LVL 3
ivan rosaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
What do you mean by active?  Enabled?
(Get-ADUser -Filter "Enabled -eq '$true'" -SearchBase "OU=microsoft=com").count

Open in new window

The "objectcategory -eq 'user'" is redundant, since we're using the Get-ADUser cmdlet.
ivan rosaAuthor Commented:
thank footech, the issue it was on the wording... i didn't know the existence of where-object

(Get-ADUser -Filter "objectcategory -eq 'user'" -SearchBase "OU=microsfot,=com" -properties * | Where-Object enabled -eq $true).count

Open in new window



i was trying to use it w/o the "objectcategory -eq 'user" but it would ask me for
cmdlet Get-ADUser at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
Filter:
footechCommented:
Yes, using Where-Object is definitely an option.  Filtering earlier is always better (more performant) so my example is preferred.  There are some limitations to what you can filter on using the -filter parameter however, so using Where-Object could be required in some scenarios.

To return all users with the Get-ADUser cmdlet, use -Filter *

Side note:  outside of testing, it's best not to use -Properties *, because that returns a lot of data.  Once you determine the attributes/properties that you need to work with (that are outside the default set), you can specify just those.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ivan rosaAuthor Commented:
Makes sense, thanks bud!
footechCommented:
Glad to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.