Powershell an Organization Unit in ADUC and get all groups with properties into csv

Crod 266 Reputation points
2020-09-25T15:59:54.487+00:00

Having some difficulties trying to powershell just a single OU in ADUC and get all groups that are in it and associated properties into a csv please.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,382 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,500 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rich Matheisen 46,241 Reputation points
    2020-09-25T18:50:00.703+00:00

    Use the -SearchBase and maybe the -SearchScope parameters on the Get-ADGroup to target your search.

    The "associated properties" can be extensive and probably not all (or even many) of them would be useful to you. Also, getting the membership of a group into a CSV isn't as simple as adding the member property to the CSV.

    You'll find lots of examples of how to do what you're asking if you search the web. Maybe not all of them will do exactly what you want, but you should be able to use them as a basis for you own script.

    If you need help with your script, post the code you're using along with a clear explanation of your goal and the particular problem you're having (including any exception messages).

    0 comments No comments

  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 35,736 Reputation points Microsoft Vendor
    2020-09-25T19:14:10.84+00:00

    Hi,

    You could use the cmdlet Get-ADGroup. Please check if this works for you.

    #Get groups in YourOU.YourDC.com  
    Get-ADGroup -Filter * -SearchBase "OU = YourOU, DC = YourDC, DC = com" -Properties *  | Export-Csv C:\YourFolder\groups.csv  
    

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

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.