Export OU inventory
Documentation: Microsoft Learn
Export Active Directory OUs to CSV with their names, distinguished names, and accidental-deletion protection settings.
The script
Script reader
Inspect before you run
Inspect the script below. It does not run in this browser.
Inspection only — no command has run.
Show reference output
Inspect this example’s structure
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Get-ADOrganizationalUnit -Filter * | Select-Object Name,ProtectedFromAccidentalDeletion,DistinguishedName | Export-Csv .\OUs.csv -NoTypeInformation- Stage 1Get-ADOrganizationalUnit
-Filter - Stage 2Select-Object
Positional values or no named parameters - Stage 3Export-Csv
-NoTypeInformation
How it works
Get-ADOrganizationalUnit with -Filter * walks every OU in the domain, Select-Object keeps the name with the ProtectedFromAccidentalDeletion flag and the distinguished name, and Export-Csv writes the file with -NoTypeInformation so no type header contaminates the first row.
Adapting it
The output path is relative, so the file lands wherever the session happened to be. Give Export-Csv an absolute path, and add a datestamp to the filename if these captures are meant to be compared over time.
Requirements
ActiveDirectory module.
If the result is unexpected
The OU export is incomplete or has unexpected path columns.
The search base can exclude part of the directory, and formatting before CSV export discards useful objects.
- Confirm SearchBase and select the desired OU properties before exporting the objects.
Validate the result
The exported row count matches the intended OU query and paths remain complete.
Keep the check reliable
Store the search base with the export and keep presentation formatting out of the data pipeline.