How to write the filter part - LDAP - in an Get-AdUser ps command ? what am i missing ?

Hello,

I'm trying to get all people but not computers out of AD with a Get-ADUser query.

Here's the filter i wanted to add to the command.
 {(&(objectclass -eq user)(!(objectclass -eq computer)))}


after adapting it for powershell here's what i came with. but it stilll not working.

Get-ADUser -filter {(objectclass -eq user) -and (objectclass -not computer)} -searchbase 'OU=E005,OU=STU,OU=TRD,DC=students,DC=tutu,DC=fr' -Properties name,lastLogonTimestamp -server student.fr.ch | select name,lastLogonTimestamp | out-gridview


thank you in advance for your help .
toshi
Erwin PombettAsked:
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.

oBdACommented:
You're overcomplicating things.
First, if objectClass is user, then objectClass can't be computer anyway, so there's no need filter for "-not computer".
Furthermore, Get-ADUser does exactly that: it returns only user objects.
So just use * as filter:
Get-ADUser -filter * -searchbase 'OU=E005,OU=STU,OU=TRD,DC=students,DC=tutu,DC=fr' -Properties name, lastLogonTimestamp -server student.fr.ch | select name, lastLogonTimestamp | out-gridview

Open in new window

Kanti PrasadCommented:
Hi

In the below link search for "All user object" to your specific question and it will also give you a complete idea

https://technet.microsoft.com/en-us/library/ee617241.aspx
Erwin PombettAuthor Commented:
hello odBA,

thank you for your answer.  This query is an exercice it's obviously not logical. but my goal is to correct this syntax.

Kanti,
thank you for answer, again, i'm looking to get the syntax of the filter ...do not pay attention to the logical.

thank you in advance.

Toshi
oBdACommented:
Since the syntax for the -Filter argument is Powershell-like, you need to enclose the attribute you're comparing with in quotes:
Get-ADUser -filter {(objectClass -eq 'User') -And (objectClass -ne 'Computer')} -searchbase 'OU=E005,OU=STU,OU=TRD,DC=students,DC=tutu,DC=fr' -Properties name, lastLogonTimestamp -server student.fr.ch | select name, lastLogonTimestamp | out-gridview

Open in new window

Or, if you want to use an ldap filter, use the argument -LDAPFilter instead of Filter:
Get-ADUser -ldapfilter "(&(objectclass=user)(!(objectclass=computer)))" -searchbase 'OU=E005,OU=STU,OU=TRD,DC=students,DC=tutu,DC=fr' -Properties name, lastLogonTimestamp -server student.fr.ch | select name, lastLogonTimestamp | out-gridview

Open in new window

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
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.