MilesLogan
asked on
Powershell - Pulling all group membership from multiple AD Accounts
I have the script below that pulls all the group membership for the users listed in the text file, but the output is not that great ...
Add-PSSnapin *Quest* -ErrorAction SilentlyContinue
$input= "e:\Projects\Users\users.t xt"
$Output = "e:\Projects\Users\Users_G roups.csv"
Get-Content $input | % {
$user = Get-QADUser -sAMAccountName $_
New-Object Psobject -Property @{"UserName"=$user.Name;"G roups"=""; "UsrSAmAcc ountName"= $user.SAmA ccountName ;"USRDescr iption"=$u ser.Descri ption;"Grp Descriptio n"=""}
ForEach ($Group in $user.memberof) {
$Grp= Get-QADGroup $group
New-Object Psobject -Property @{"UserName"="";"Groups"=$ Grp.Name;" UsrSAmAcco untName"=" ";"USRDesc ription"=" ";"GrpDesc ription"=$ Grp.Descri ption}
}
} | Export-CSV -Path $Output -NoTypeInformation
Does anyone have one that pulls the data to similar to what is listed below ?? so basically I need the SamAccountName to be one each row next to each group it is a member of.
Name SamAccountName Groups Group Description
Test User ABC123 AccessGroup1
ABC123 AccessGroup2
ABC123 AccessGroup3
ABC123 AccessGroup4
TestUser2 ABC456 AccessGroup5
ABC456 AccessGroup6
ABC456 AccessGroup7
Capture1.PNG
Add-PSSnapin *Quest* -ErrorAction SilentlyContinue
$input= "e:\Projects\Users\users.t
$Output = "e:\Projects\Users\Users_G
Get-Content $input | % {
$user = Get-QADUser -sAMAccountName $_
New-Object Psobject -Property @{"UserName"=$user.Name;"G
ForEach ($Group in $user.memberof) {
$Grp= Get-QADGroup $group
New-Object Psobject -Property @{"UserName"="";"Groups"=$
}
} | Export-CSV -Path $Output -NoTypeInformation
Does anyone have one that pulls the data to similar to what is listed below ?? so basically I need the SamAccountName to be one each row next to each group it is a member of.
Name SamAccountName Groups Group Description
Test User ABC123 AccessGroup1
ABC123 AccessGroup2
ABC123 AccessGroup3
ABC123 AccessGroup4
TestUser2 ABC456 AccessGroup5
ABC456 AccessGroup6
ABC456 AccessGroup7
Capture1.PNG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you much fooTech ..
I changed the line to "UsrSAmAccountName"=$user. SAmAccount Name; and it changed the output to what I needed .. thanks !
I changed the line to "UsrSAmAccountName"=$user.
You're welcome.
Thanks,
Dan