Solved

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

Posted on 2009-04-01
7
678 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
 
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

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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 from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now