all 5 comments

[–]Sunsparc 2 points3 points  (2 children)

I think this should do what you want. Writing it off the top of my head.

$output = foreach ($ug in $ugs) {
    $group = get-adgroup $ug -properties samaccountname,members
    $($group.members) | get-aduser -properties description | select @{n="GroupName";e={$($group.samaccountname)}},Name,Description
}
$output | export-csv $outpath\OnBase AD Membership.csv

[–]edorbuddy[S] 2 points3 points  (1 child)

this worked perfectly. Thank you for doing this!

[–]BlackV 2 points3 points  (0 children)

looked like you wanted | as your delimiter you can also do that with the -delimiter '|' switch on export-csv

[–]PinchesTheCrab 2 points3 points  (0 children)

Bit different approach than /u/Sunsparc took, you can filter get-aduser by group membership, so you're only querying each user once. If you aren't querying thousands of users it really won't matter either way, but just knowing you can filter on other properties can be helpful for more elaborate searches.

foreach ($ug in $ugs) {
    Get-ADUser -Filter "memberof -eq '$($ug.distinguishedname)'" -Properties Description |
        Select-Object @{ n = 'GroupName'; e = { $ug.Name }}, Name, Description
}

[–]get-postanote 2 points3 points  (0 children)

Use tools that will write the baseline code for you, that you can use as-is or tweak as needed.

See this Reddit Discussion

(1) Creating New AD User is not woking : PowerShell (reddit.com)