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

This topic contains 5 replies, has 4 voices, and was last updated by  Paul Goretti 3 years, 7 months ago.

  • Author
  • #21268

    Paul Goretti

    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

  • #21269

    Ondrej Zilinec

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

  • #21270

    Stephen Owen

    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 *
  • #21272

    Paul Goretti

    I think i have it 😉 Thanks for your input

  • #21273

    Richard Siddaway

    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

  • #21274

    Paul Goretti

    Thanks Stephen,

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

You must be logged in to reply to this topic.