Forum Discussion
manideepkarnati
Dec 06, 2022Copper Contributor
Finding groups with mixed accounts
Hey All, Is there a way to easily query/fetch all the security groups which contain users with particular format, let say "user_department". #powershell
1 Reply
- VGSandzCopper Contributor
If you are looking for Group Names, a specific user is part of who match specific 'Department' attribute, you could try this,
In this example, the users have the 'Department' attribute value as "IT"
#Query Users in Domain matching "Department" attribute as "IT". $users = Get-ADUser -Filter {Department -eq "IT"} foreach( $user in $users) { $DN = (Get-ADUser -Identity $user -Properties DistinguishedName).DistinguishedName $groupUserPartOf = ((Get-ADGroup -LDAPFilter "(member:1.2.840.113556.1.4.1941:=$($DN))").Name) Write-Output "User $user is part of the following groups:" $groupUserPartOf }
try with a small subset of users attributes, validate in your test landscape.