0

I have been trying to understand how to import my csv file and export of specific adgroup they are added or even they are not added

Import-CSV " C:\Users\user.csv" | ForEach-Object { Get-ADGroupMember $_. sAMAcountName -Properties * |Select sAMAcountName } |Export-CSV "c:\Users\userswithgroup.csv"

I dont really understand why its not working what went wrong.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
K0n2113
  • 11
  • 1

1 Answers1

3

I think your main issue is that you're using Get-ADGroupMember rather than what you need which is Get-ADPrincipalGroupMembership

You use Get-ADGroupMember to query a group and find out who is a member of it, but in your case you're passing a username to it not a group name, so it won't find anything. So you'd want something like :

Import-CSV " C:\Users\user.csv" | ForEach-Object { Get-ADPrincipalGroupMember $_.sAMAcountName |Select Name }

which should then return the group memberships of each of the users listed in the .csv file, assuming that's appropriately formatted.

Keith Langmead
  • 857
  • 1
  • 7
  • 14