Ron Shorts
asked on
Powershell script to output if user part of AD group/s
I have the below script that pulls from a list and outputs to a csv the samaccountname and mail attributes.
What I'm trying to do is next to each user check if each user is a member of a certain AD Group, or two AD Groups actually, for this example, the name of the two groups would be "GroupA" and "GroupB"
So the output would be, listing the name of the two groups I want to check in columns 3 and 4:
sAMAccountName mail GroupA GroupB
-------------------------- ------- -------------- --------------
user1 user1@domain.com GroupA
user2 user2@domain.com GroupB
Assuming user1 is a member of GroupA and user2 is a member of GroupB
Thanks,
Ron
What I'm trying to do is next to each user check if each user is a member of a certain AD Group, or two AD Groups actually, for this example, the name of the two groups would be "GroupA" and "GroupB"
So the output would be, listing the name of the two groups I want to check in columns 3 and 4:
sAMAccountName mail GroupA GroupB
--------------------------
user1 user1@domain.com GroupA
user2 user2@domain.com GroupB
Assuming user1 is a member of GroupA and user2 is a member of GroupB
Import-Csv -Path C:\Temp\users.csv | ForEach-Object {
Get-ADUser -Filter "(sAMAccountName -eq '$($_.sAMAccountName)')" -Properties sAMAccountName,mail | Select-Object sAMAccountName,mail
} | Export-CSV mailusers.csv -NoTypeInfo
Thanks,
Ron
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER