Getting AD output that shows a users first and last name and department :)

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 :slight_smile:

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
    • CategoryInfo : ObjectNotFound: (:slight_smile: [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

This error is caused by mistake in SearchBase parameter. Something is bad in your AD Path “ou=xxxxxxx,ou=xxx xxxx,ou=xxxxx,dc=erc,dc=insider”.

Well, the error in your error text says ‘properties Departme’. 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 *

I think i have it :wink: Thanks for your input

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

Thanks Stephen,

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