I have an issue with some query parts dues to some failures in the system so basically, I have to search all AD users, and check which user is member of a specific group. Using the Get-ADgroupMember does not return anything as I can not query in the specific group, I have to work around it such as checking users and checking if they are members of the group and if so, listing them into a csv/txt file.
Any ideas on how to tackle this one?
$users= Get-ADUser -Filter {name -like "" } -Properties memberof $Groups= Get-ADGroup -Filter {name -like "" } -Properties memberof Select-Object -ExpandProperty memberof | where memberof -EQ "Users" Foreach( $user in $users) {
$grups= $user | Select-Object -ExpandProperty memberof
If( $grups -contains "Users,OU=txx,OU=Admin,DC=COM,DC=Digital") { Add-ADGroupMember "Users" -Members $user.Samaccountname } } Foreach( $grup in $groups ) {
$member = $grup | Select-Object -ExpandProperty memberof If( $member -contains "Users,OU=txx,OU=Admin,DC=COM,DC=Digital") { Add-ADGroupMember "Users" -Members $grup.Name } }
Found the solution.