Solved

A Script to audit AD to show every user, with every group they are in

Posted on 2009-04-01
7
681 Views
Last Modified: 2013-12-24
Hi,
I have been give the above task, i immediately thought of powershell, which i am still a novice at. I just prefer the one liners to get the job done.
I borrowed and burgled some code to get the below:

function func_Member_of()
{
# Builds a group membership for a given user, computer or group
# Returns only direct group membership

$input | ForEach-Object {
      if ($_.primaryGroupID) {
            $_.SID.Value -replace '-\d+$',"-$($_.PrimaryGroupID)" |Get-QADGroup -Connection $_.Connection
      }
      if ($_.memberOf) {
            $_.memberOf | Get-QADGroup -Connection $_.Connection
      }
}
}


 Get-QADUser -SizeLimit 0 -ErrorAction SilentlyContinue | func_Member_of | Select-Object -Property `
"name","Office","group","company" |Export-Csv c:\adgroup.csv

This unfortunately only returns the groups, no mention of the users or any of the other parameters i would like to sort on further down the line.
I figure that the fuction needs to be expanded to accommodate this.

If you have an answer thats not PS, thats fine.

Thanks in advance.
0
Comment
Question by:cplit
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 24045665
change

if ($_.memberOf) {
            $_.memberOf | Get-QADGroup -Connection $_.Connection
      }

to

if ($_.memberOf) {
            $_.memberOf | Get-QADObject -Connection $_.Connection
      }
0
 

Author Comment

by:cplit
ID: 24045824
Hi BSonPosh,
That has cleaned up the group names, thanks for that.
There is still the issue of a long list of groups (approx 4000), but it still doesn't show the users.

All i have managed to show with this script is a long list of groups.
I also need to show the users relative to their group membership.

The script seems to order the groups the right way (per user), but the user has been omitted from the output.
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 24045945
Doh!... not sure what I was thinking. memberof only contains groups :)
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 18

Expert Comment

by:BSonPosh
ID: 24046035
if you are in a single domain try this

Get-QADUser -sl 0 -ea 0| Select-Object name,Office,group,company,TokenGroups | Export-Csv c:\adgroup.csv -NoType
0
 
LVL 18

Accepted Solution

by:
BSonPosh earned 500 total points
ID: 24046083
whoops.. that doesn't work

try this
Get-QADUser -sl 0 -ea 0| Select-Object name,Office,group,company,@{n="Groups";e={$_.TokenGroups | %{$_.Name}}} | export-csv C:\temp\adgroup2.csv -NoType

Open in new window

0
 

Author Comment

by:cplit
ID: 24046424
BSonPosh,
Thanks so much for your prompt help.
That worked a treat

Thanks again
0
 

Author Closing Comment

by:cplit
ID: 31565595
Thanks
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

785 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