Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update win_domain_group_membership.ps1 #56953

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/ansible/modules/windows/win_domain_group_membership.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,19 @@ foreach ($member in $members) {
}

if ($state -in @("present", "pure") -and !$user_in_group) {
Add-ADGroupMember -Identity $name -Members $group_member -WhatIf:$check_mode @extra_args
try {
Add-ADGroupMember -Identity $name -Members $group_member -WhatIf:$check_mode @extra_args
} catch {
Fail-Json $result "Failed to add a group $($group_member): $($_.Exception.Message)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A silly comment but probably should be Failed to add group $($group_member): $($_.Exception.Message) or Failed to add a group: $($group_member) - $($_.Exception.Message)

}
$result.added.Add($group_member.SamAccountName)
$result.changed = $true
} elseif ($state -eq "absent" -and $user_in_group) {
Remove-ADGroupMember -Identity $name -Members $group_member -WhatIf:$check_mode @extra_args -Confirm:$False
try {
Remove-ADGroupMember -Identity $name -Members $group_member -WhatIf:$check_mode @extra_args -Confirm:$False
} catch {
Fail-Json $result "Failed to remove a group $($group_member): $($_.Exception.Message)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the add comment

}
$result.removed.Add($group_member.SamAccountName)
$result.changed = $true
}
Expand All @@ -94,7 +102,11 @@ if ($state -eq "pure") {
}

if ($user_to_remove) {
Remove-ADGroupMember -Identity $name -Members $current_member -WhatIf:$check_mode @extra_args -Confirm:$False
try {
Remove-ADGroupMember -Identity $name -Members $current_member -WhatIf:$check_mode @extra_args -Confirm:$False
} catch {
Fail-Json $result "Failed to remove a group $($group_member): $($_.Exception.Message)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here as well, regarding the grammar/text

}
$result.removed.Add($current_member.SamAccountName)
$result.changed = $true
}
Expand Down