Skip to content

Commit

Permalink
fix big group problem (#204)
Browse files Browse the repository at this point in the history
* fix big group problem

* fix syntax to pass tests

* Update win_domain_group_membership.ps1

* fix as suggested by @jborean93

* Added changelog fragment

Co-authored-by: Jordan Borean <[email protected]>
  • Loading branch information
baldator and jborean93 authored May 11, 2021
1 parent 4c8c11c commit 72e4a1a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/win_domain_group_membership-large.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- win_domain_group_membership - Handle timeouts when dealing with group with lots of members - https://github.com/ansible-collections/community.windows/pull/204
10 changes: 6 additions & 4 deletions plugins/modules/win_domain_group_membership.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ if ($diff_mode) {
$result.diff = @{}
}

$members_before = Get-AdGroupMember -Identity $ADGroup @extra_args
$filter = "(memberOf=$($ADGroup.DistinguishedName))"

$members_before = Get-ADObject -LDAPFilter $filter -Properties sAMAccountName, objectSID @extra_args
$pure_members = [System.Collections.Generic.List`1[String]]@()

foreach ($member in $members) {
Expand Down Expand Up @@ -89,7 +91,7 @@ foreach ($member in $members) {

if ($state -eq "pure") {
# Perform removals for existing group members not defined in $members
$current_members = Get-AdGroupMember -Identity $ADGroup @extra_args
$current_members = Get-ADObject -LDAPFilter $filter -Properties sAMAccountName, objectSID @extra_args

foreach ($current_member in $current_members) {
$user_to_remove = $true
Expand All @@ -101,14 +103,14 @@ if ($state -eq "pure") {
}

if ($user_to_remove) {
Remove-ADPrincipalGroupMembership -Identity $current_member -MemberOf $ADGroup -WhatIf:$check_mode -Confirm:$False
Remove-ADPrincipalGroupMembership -Identity $current_member -MemberOf $ADGroup -WhatIf:$check_mode -Confirm:$False @extra_member_args
$result.removed.Add($current_member.SamAccountName)
$result.changed = $true
}
}
}

$final_members = Get-AdGroupMember -Identity $ADGroup @extra_args
$final_members = Get-ADObject -LDAPFilter $filter -Properties sAMAccountName, objectSID @extra_args

if ($final_members) {
$result.members = [Array]$final_members.SamAccountName
Expand Down

0 comments on commit 72e4a1a

Please sign in to comment.