Get-ADUser from OU

Joel Heideman 136 Reputation points
2023-04-18T15:40:51.47+00:00

This script works fine against the entire directory -

Get-ADUser -filter * -properties * | select-object DisplayName, Mail, Created, lastlogonDate | sort Name | export-csv C:\temp\Accounts.csv -NoTypeInformation But, when I filter an OU it does not pull the same information - any ideas?

get-aduser -filter * -searchbase "OU=IBM Users,OU=Users,DC=IBM,DC=com" -Properties * |     select-object DisplayName, mail, created, lastlogondate  | sort Name | export-csv C:\temp\Accounts.csv -NoTypeInformation

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,901 Reputation points
    2023-04-18T19:40:22.8833333+00:00

    Your first example is getting all AD users in a DOMAIN. Your second example is getting all AD users in an organizational unit named "IBM Users" (and any of its child OUs).

    If you want to ignore the contents of "IBM User"s child OUs, add -SearchScope Onelevel to the Get-ADUsers cmdlet in the second example.


1 additional answer

Sort by: Most helpful
  1. Boris Von Dahle 3,221 Reputation points
    2023-04-18T18:52:13.2233333+00:00

    Hello,

    Your second script should work correctly if you've specified the correct search base.

    Can you please make sure you've entered the correct DN for the OU, it seems really weird to have twice Users and IBM in there, i think you mean :
    "OU=Users,DC=IBM,DC=com".
    If that was usefull please mark the answer as accepted for other users to find this topic. Regards


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.