1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

win_group_membership - fix random issue with CI on 2012 R2 (#45462)

This commit is contained in:
Jordan Borean 2018-09-11 13:07:43 +10:00 committed by GitHub
parent 881f3a599c
commit 3371a779b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- win_group_membership - fix intermittent issue where it failed to convert the ADSI object to the .NET object after using it once

View file

@ -46,16 +46,24 @@ function Get-GroupMember {
[System.DirectoryServices.DirectoryEntry]$Group [System.DirectoryServices.DirectoryEntry]$Group
) )
$members = @() # instead of using ForEach pipeline we use a standard loop and cast the
# object to the ADSI adapter type before using it to get the SID and path
$current_members = $Group.psbase.Invoke("Members") | ForEach-Object { # this solves an random issue where multiple casts could fail once the raw
$bytes = ([ADSI]$_).InvokeGet("objectSID") # object is invoked at least once
$sid = New-Object -TypeName Security.Principal.SecurityIdentifier -ArgumentList $bytes, 0 $raw_members = $Group.psbase.Invoke("Members")
$adspath = ([ADSI]$_).InvokeGet("ADsPath") $current_members = [System.Collections.ArrayList]@()
foreach ($raw_member in $raw_members) {
@{sid = $sid; adspath = $adspath} | Write-Output $raw_member = [ADSI]$raw_member
$sid_bytes = $raw_member.InvokeGet("objectSID")
$ads_path = $raw_member.InvokeGet("ADsPath")
$member_info = @{
sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList $sid_bytes, 0
adspath = $ads_path
}
$current_members.Add($member_info) > $null
} }
$members = @()
foreach ($current_member in $current_members) { foreach ($current_member in $current_members) {
$parsed_member = @{ $parsed_member = @{
sid = $current_member.sid sid = $current_member.sid