Author Posts

December 17, 2014 at 5:45 am

Hello from a Powershell newbie!

I've had a look around but not found exaclty what I'm looking for so thought I'd post. I'm trying to use this simple script to extract a first and last name for each user in a given OU. I want to list each user in each OU in my AD tree but so far, I cant get it to work correctly. Any help is greatly appreciated 🙂

code : Get-ADUser -searchbase “ou=xxxxxx,ou=xxx xxx,ou=xxxx,dc=mydomain,dc=com” -filter * -Properties Department

The error I get is:

Get-ADUser : Directory object not found
At line:1 char:11
+ get-Aduser <<<< -searchbase "ou=xxxxxxx,ou=xxx xxxx,ou=xxxxx,dc=mydomain,dc=com" -filter * -properties Departme nt + CategoryInfo : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : Directory object not found,Microsoft.ActiveDirectory.Management.Commands.GetADUser I"m really not sure whats wrong here so really appreciate your time! Thanks and Regards

December 17, 2014 at 5:54 am

This error is caused by mistake in [b]SearchBase[/b] parameter. Something is bad in your AD Path [b]"ou=xxxxxxx,ou=xxx xxxx,ou=xxxxx,dc=erc,dc=insider"[/b].

December 17, 2014 at 6:00 am

Well, the error in your error text says 'properties [b]Departme[/b]'. Looks like a typo!

Generally you should start simple and then tighten up for net/filtering as you refine your code.

Does this command work?

 get-aduser -ResultSetSize 10 -filter *

December 17, 2014 at 6:02 am

I think i have it 😉 Thanks for your input

December 17, 2014 at 6:09 am

Your code needs to look like this

Get-ADUser -Filter * -SearchBase 'OU=Testing,DC=Manticore,DC=org' -Properties GivenName, Surname, Department | select GivenName, SurName, Department

December 17, 2014 at 6:16 am

Thanks Stephen,

Department is just wrapped round 🙂 I had a small cmd window open.