Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Active Directory Powershell ADGroup Report incl. 'Description Field'

Posted on 2014-03-19
4
Medium Priority
?
2,782 Views
Last Modified: 2014-03-19
Hi All,

Huge thanks in advance for your help, Experts Exchange has almost literally never let me down.

I'm grappling with a powershell script intended to produce a report that exports to CSV all of the Groups within an OU as well as each groups memberships. The other catch is that I need the 'Description' field to come out with the report. In my mind ideally the csv resemble something akin to:

GroupName, MemberName, GroupDescription
Contoso Admins, Joe Bloggs, "Admins of the Contoso Network"
Contoso Admins, John Smith, "Admins of the Contoso Network"
Contoso Finance, John Doe, "Contoso Finance Staff"

OR

GroupName, MemberName, GroupDescription
Contoso Admins, Joe Bloggs, John Smith, Jane Doe, "Admins of the Contoso Network"
Contoso Finance, John Doe, "Contoso Finance Staff"

I'm hesitant to even post my recent attempts, I'm sure they are fairly shameful.

Any suggestions are very welcome.

Thank you again,

Adam
0
Comment
Question by:aroddick
  • 3
4 Comments
 
LVL 2

Author Comment

by:aroddick
ID: 39941520
If it helps - I've done an 'Export List' of the OUs in question to a csv which includes the Group 'friendly' Name and the Description so...

Is there is a way to parse the contents of one of those csv files through to a Get-ADMember command somehow to generate something useful?
0
 
LVL 41

Accepted Solution

by:
footech earned 2000 total points
ID: 39941534
This is pretty simple.  The key here is using calculated properties.
Get-ADGroup -filter * -Properties description | select name,description | % { 
  $gname = $_.name
  $gdesc = $_.description
  Get-ADGroupMember $gname | Select @{n="GroupName";e={$gname}},@{n="MemberName";e={$_.name}},@{n="GroupDescription";e={$gdesc}} } | Export-CSV somefile.csv -notype

Open in new window

If you need to limit to a particular OU, you can use the -searchbase parameter of Get-ADGroup.  If you have multiple OUs to query, then you could either read those from a file, or create an array with them in it, and then pipe that array to a foreach loop for Get-ADGroup to act on.
0
 
LVL 2

Author Comment

by:aroddick
ID: 39941550
Get-ADGroup -filter * -SearchBase $OU -Properties description | select name,description | % { 
  $OU="OU=Security Groups,OU=Australia,DC=contoso,DC=com,DC=au"
  $gname = $_.name
  $gdesc = $_.description
  Get-ADGroupMember $gname | Select @{n="GroupName";e={$gname}},@{n="MemberName";e={$_.name}},@{n="GroupDescription";e={$gdesc}} } | Export-CSV C:\Final.csv -notype

Open in new window


Much simpler than the methods I was playing with. I've just added a -SearchBase filter to limit to the OU I want to scan. Perfecto.

Thank you very much mate, sincerely appreciated!

Adam
0
 
LVL 2

Author Closing Comment

by:aroddick
ID: 39941551
Perfect mate. Sincerely appreciated.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question