How to get a list of OUs in AD using PowerShell scripts
The following is a comparison between obtaining a list of OUs in AD with Windows PowerShell and ADManager Plus:
Steps to obtain list of OUs in AD using PowerShell:
- Identify the domain from which you want to retrieve the report.
- Identify the LDAP attributes you need to fetch the report.
- Compile the script.
- Execute it in Windows PowerShell.
- The report will be exported in the given format.
- To obtain the report in a different format, modify the script accordingly to the needs of the user.
Sample Windows PowerShell script
Click to copy entire script
Get-ADOrganizationalUnit -Filter'Name -like "*"' | Format-Table Name, DistinguishedName -B
To obtain a report:
- Select All OUs from OU Reports -> Reports tab.
- Select the domain and click Generate.
- Select Export as to export the report in any of the preferred formats (CSV, PDF, HTML, CSVDE and XLSX).
» Start 30-day Free Trial
- We can run this script only from the computers which has Active Directory Domain Services role.
- Adding even minor modifications to a script—such as adding additional attributes to the reports—require it to be modified and executed again, which is time-consuming.
- For each format type, a script has to be modified accordingly to export in that format, leading to increased LDAP query complexity in these scripts.
- Troubleshooting these scripts requires extensive AD and scripting expertise.
ADManager Plus will retrieve details of OUs in any desired format in a simple and intuitively designed UI.