I'm looking to export some data, in particular an AD user along with their AD groups.
My current code:
$users = import-csv -path C:\path
foreach ($user in $users) {
$user | select name,SamAccountName | ft
Get-ADPrincipalGroupMembership $user.samaccountname | select name
#export-csv -path C:\path-NoTypeInformation -Append
}
The issue i'm having is whenever I try to export this information i'm only exporting the group output whereas I need the username to see who these groups actually belong to.
Perhaps there's a better method to achieve this?