Script for getting AD user information

AhmedAliShaik
AhmedAliShaik used Ask the Experts™
on
Team,

I need to get the list of AD users in my domain with a criteria. If the custom attribute 1 and 5 are equal i should get the total number of users count.

get-user -Resultsize unlimited -organizationalunit mydomain.com/Users -filter {((customAttribute6 -like '76*') -and (customAttribute6 -like 'Vehicle*'))}| Measure-Object).Count

When executing the count i am getting the below error:

The term 'customAttribute6' is not recognized as the name of a cmdlet, function
, script file, or operable program. Check the spelling of the name, or if a pat
h was included, verify that the path is correct and try again.
At line:1
+ get-user -resultsize unlimited -OrganizationalUnit mydomain.com/users -Filter
(customAttribute6 <<<<  -like '76*')
    + CategoryInfo          : ObjectNotFound: (customAttribute1:String) [], Co
   mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Is there a way i can use custom attribute to retrieve AD users list.

Please help me in executing the cmd.

Thanks in Advance.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012
Commented:
Have you tried this one

(Get-ADUser -SearchBase "cn=users,dc=mydomain,dc=com" -filter { (customAttribute6 -like "76*") -and (customAttribute6 -like "Vehicle") } | Measure-Object).Count

Open in new window


Regards,
Krzysztof

Author

Commented:
Krzysztof ,

I will try this and post u with updates.

Author

Commented:
Hi Krzysztof ,

I believe Get-ADuser is a Quest cmdlet.

I am able to resolve only get-user even no luck with the command.

Can u revise and give me a windows/Exchange powershell command for the same.
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Krzysztof PytkoSenior Active Directory Engineer
Top Expert 2012

Commented:
No, Get-ADUser is a Windows Server 2008R2 PowerShell module for AD. Do you have 2008R2 DC ? If not, which PowerShell version do you use ?

Krzysztof
Senior Active Directory Engineer
Top Expert 2012
Commented:
OK, for Exchange Management Shell (EMS) try this syntax

(Get-ADUser -OrganizationalUnit "mydomain.com/Users" -filter { (customAttribute6 -like "76*") -and (customAttribute6 -like "Vehicle") } -ResultSize "unlimited"| Measure-Object).Count

Open in new window


in case that -ResultSize "unlimited" doesn't work try to use it without quotes.

Krzysztof

Author

Commented:
Thanks you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial