Get users Group and members of the groups

$AllUSers = get-aduser -filter {SamAccountName -like “z*” -and Enabled -eq $true } -Properties Memberof,EmployeeNumber -Server <Domain name> | ?{$PSItem.DistinguishedName -notmatch “OU=Service Accounts”}

$results = new-object System.Collections.ArrayList

foreach($user in $AllSers){

$grps = $user.MemberOf

$v = New-Object System.Collections.ArrayList

foreach($grp in $grps){

$Gobj = Get-ADGroup $grp -Server <Servername:3268> -Properties GroupCategory,GroupScope,Name | select @{l=”GroupName”;e={(($PSItem.DistinguishedName -split “,DC=”)[1])+”\”+$PSItem.SamAccountName}},GroupCategory,GroupScope

$l = $Gobj.GroupName+”,”+ $Gobj.GroupScope +”,”+ $Gobj.GroupCategory

$v.Add($l)

}

$o = [pscustomobject]@{

SamAccountName = $user.SamAccountName

#ProdEmail = $user.EmployeeNumber

Name = $user.GivenName + ” ”  +$user.Surname

DevUPN = $user.UserPrincipalName

‘Groups(Name,Scope,Category)’ = $v -join “;”

“Memberof(RawData)” = $user.MemberOf -join “;”

}

$results.Add($o)

}

$results | export-csv C:\Temp\User_Groups.csv -NoTypeInformation

18 Comments

  1. Very efficiently written article. It will be supportive to anybody who usess it, as well as yours truly :). Keep doing what you are doing – can’r wait to read more posts.

  2. I intended to post you that very small note in order to give many thanks as before over the remarkable methods you’ve contributed on this page. It is quite remarkably open-handed with you to supply unreservedly exactly what a number of people could have sold as an e book to help with making some dough for their own end, specifically given that you might have tried it if you decided. The points in addition served to become a great way to fully grasp that some people have the same zeal similar to my personal own to know the truth much more on the topic of this matter. I’m certain there are lots of more fun periods ahead for people who find out your blog.

  3. The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my choice to read, but I actually thought youd have something interesting to say. All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

  4. I would like to point out my affection for your kindness supporting those who absolutely need assistance with your issue. Your special dedication to getting the message all around turned out to be extraordinarily powerful and have all the time helped associates like me to reach their ambitions. Your new informative suggestions denotes a whole lot a person like me and somewhat more to my colleagues. With thanks; from everyone of us.

  5. That is the correct blog for anyone who wants to search out out about this topic. You notice a lot its virtually onerous to argue with you (not that I really would want…HaHa). You positively put a brand new spin on a subject thats been written about for years. Nice stuff, just great!

Leave a Reply

Your email address will not be published.