Share via


Getting an AD user from specific OU using Powershell

Question

Thursday, March 1, 2018 5:15 PM

Hello,

I have my search base path in $path and I am trying to get specific user from AD and the search base is $path

I have following code and it doesnot seem to work:

$User=Get-Aduser -SearchBase $path -Filter * -properties Name | Where { ($_.Name) -eq $i.Name}

-SearchBase $path Doesnot seem to work.

Thanks.

All replies (7)

Thursday, March 1, 2018 5:23 PM | 3 votes

How are you defining $Path?  It should the distinguished name, for example:

$path = "ou=users,dc=mydomain,dc=local"

This works for me on Windows Server 2016 (I didn't include the rest as I don't know what you are using for $I):

$path = "OU=Service accounts,OU=Users,OU=WebbWorld,DC=webbworld,DC=local"$users = get-aduser -SearchBase $path -filter * -properties name

Thursday, March 1, 2018 5:40 PM

Doesnot work !!


Thursday, March 1, 2018 5:53 PM

Then provide more information.  Show your full script, tell us what "does not work" means, and answer my question.


Thursday, March 1, 2018 6:33 PM

Are u actually getting anything if u just run 

Get-Aduser -SearchBase $path -Filter *    

??


Thursday, March 8, 2018 9:10 AM

Hi,

Just check the situation about your issue.

Best Regards,
Frank

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Monday, March 12, 2018 9:58 AM

Hi,

Was your issue resolved? 

If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
If no, please reply and tell us the current situation in order to provide further help.

Best Regards,
Frank

Please remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact [email protected]


Thursday, June 6, 2019 2:34 AM

This definitely works. I propose this as an answer.