Help with member of script

So i am trying to pull from a list of users and get their group memberships. It’s taken me some time to get what i have but it works except for the part of the csv export that instead of having the username of the user it has everything from the the user csv (name,Samaccount,DN,email) any idea what i am doing wrong? The csv export has group name, category,DN, then under the next column which i named Username is has the users samaccount name,DN,Email all under one column (which are all in my import csv). I only need the user name in that column. Another thing i noticed is if i type $f i get all the info that’s my csv that i am pulling from.

Import-Module ActiveDirectory $List = "C:UsersI030743DesktopADusers_test.csv" $output = "C:UsersI030743DesktopADMEMBERS_TEST.csv" $File = Import-CSV $List Foreach ($f in $file) {Get-ADPrincipalGroupMembership -Identity $f.sAMAccountName | Select Name,GroupCategory,DistinguishedName,@{name='UserName';Expression={$f}} | Export-CSV $output -NoTypeInformation -Encoding ASCII -force -append } 

submitted by /u/typo13
[link] [comments]

Leave a Reply