Export a list of all groups 2 users are a member of

I am needing to export 2 AD users and groups they are members of. Is there a way of accomplishing this with one export? I would like 2 columns, 1 for each user and the groups.

Get-AdPrincipalGroupMembership e56836 | select name | sort-object -Property name

What exactly do you mean with that? Get-AdPrincipalGroupMembership does not take arrays for the -Identity parameter. So you’d need any kind of loop.

This will work:

$IdentityList = 'UserOne','UserTwo'
foreach($Identity in $IdentityList){
    [PSCustomObject]@{
        Name = $Identity
        Groups = (Get-ADPrincipalGroupMembership -Identity $Identity).Name -join ', '
    }
}

Thanks that is perfect. Is there a way to export that out to a csv?

That’s a joke, isn’t it? :thinking:

How long would it have taken you to try it?