Export information from AD

Glenn Maxwell 14,206 Reputation points
2026-07-12T18:00:38.9633333+00:00

Hi all,

I need to export all Active Directory groups from a specific OU, including all of its nested (child) OUs.

My Active Directory structure is similar to the following: my.domain-int.com\Groups

my.domain-int.com
└── OU=Groups
    ├── OU=SubOU1
    │   ├── OU=ChildOU1
    │   └── OU=ChildOU2
    ├── OU=SubOU2
    └── OU=SubOU3

I want to export all AD groups located under OU=Groups, including groups in all child and nested OUs.

The output should include the following attributes:

  • Group Name
  • Group Type (Security or Distribution)
  • Description
  • OU path (Organizational Unit where the group resides)

Could someone please provide a PowerShell script to export this information to a CSV file?

Windows for business | Windows Server | Directory services | Active Directory
0 comments No comments

Answer accepted by question author
VPHAN 43,820 Reputation points Independent Advisor
2026-07-12T18:43:59.3033333+00:00

Hi Glenn Maxwell,

Import-Module ActiveDirectory
$searchBase = "OU=Groups,DC=my,DC=domain-int,DC=com"
$outputPath = "C:\path\to\exported_groups.csv"
Get-ADGroup -Filter * -SearchBase $searchBase -SearchScope Subtree -Properties Description | Select-Object Name, GroupCategory, Description, @{Name="OU Path"; Expression={($_.DistinguishedName -split '(?<!\\),', 2)[1]}} | Export-Csv -Path $outputPath -NoTypeInformation -Encoding UTF8

You can safely execute this script in an elevated PowerShell console on a domain-joined machine. The script extracts the exact parent structural path by processing the distinguished name property with a calculated regular expression, splitting the string perfectly to remove the group's relative name while preserving the actual directory location. Be sure to replace the placeholder search base string with the exact distinguished name of your target organizational unit and update the local C:\ drive destination path for the CSV output file.

Hope this answer has brought you some useful information. If it did, please hit “accept answer”. Should you have any questions, feel free to leave a comment.

VPHAN

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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