Generate a list of AD Users and their OU
Full-Access Members Only
Sorry, this lesson is only available to Server Academy Full-Access members. Become a Full-Access member now and get instant access to this and many more premium courses. Click the button below and get instant access now.
Instructions
Q&A (0)
Notes (0)
Resources (0)
Saving Progress...
Resources
There are no resources for this lesson.
Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.
In this lecture, we are going to use Windows PowerShell to generate a list of AD Users in their respective Organizational Units. This was a request by a student and I always love creating content that you guys want!
To get started, we will use the Get-ADUser command. We are required to pass a filter, and in this case I am going to use “*” with the quotes as my filter:
Get-ADUser -filter “*”
This returns all of the Active Directory users in our domain. We could use the “DistinguishedName” property to find their OU, but that isn’t the most human readable. There is another property that might work better called the “CanonicalName”. We can include this property by using the “-properties CanonicalName” parameter.
Get-ADUser -filter “*” -properties CanonicalName
We can see that this returns an easier-to-read path. So now we need to filter the results so we only get what information we want. I am going to pipe the above command to the select-object select the objects Name, SamAccountName, CanonicalName, and Enabled:
Get-ADUser -filter “*” -properties CanonicalName | select-object Name, SamAccountName, CanonicalName, Enabled
Now we have our list of users and their OU location. If we want to export this we can again pipe the output of this command to the Export-CSV command like so:
Get-ADUser -filter “*” -properties CanonicalName | select-object Name, SamAccountName, CanonicalName, Enabled | Export-CSV -Path “C:\ADUsers.csv”
The CSV file looks like this:
If you add -NoTypeInformation your CSV file will not include the first line:
Get-ADUser -filter “*” -properties CanonicalName | select-object Name, SamAccountName, CanonicalName, Enabled | Export-CSV -Path “C:\ADUsers.csv” -NoTypeInformation
Server Academy Members Only
Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.