diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cb5d254..9d368361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - xPSDesiredStateConfiguration - Updated CI pipeline to remove Azure DevOps deprecated Windows Server 2016 image and add Windows Server 2022 - Fixes [Issue #752](https://github.com/dsccommunity/xPSDesiredStateConfiguration/issues/752). +- xGroup + - Workaround added for the [Issue #750](https://github.com/dsccommunity/xPSDesiredStateConfiguration/issues/750) The resource could fail with the 'Exception calling "Add" with "1" argument(s): "The network path was not found."' The workaround is to catch the exception and try to use another programmatic method to update group members. ### Fixed diff --git a/source/DSCResources/DSC_xGroupResource/DSC_xGroupResource.psm1 b/source/DSCResources/DSC_xGroupResource/DSC_xGroupResource.psm1 index c6f97175..b4dd0d47 100644 --- a/source/DSCResources/DSC_xGroupResource/DSC_xGroupResource.psm1 +++ b/source/DSCResources/DSC_xGroupResource/DSC_xGroupResource.psm1 @@ -2508,6 +2508,11 @@ function Clear-GroupMember .PARAMETER MemberAsPrincipal The member to add to the group as a principal. + .NOTES + There is an issue reported at https://github.com/PowerShell/PSDscResources/issues/82 + If local group already has members from trusted forests/domains, the Add method fails + The exact reason of the failure is unknown at the moment and as a workaround try-catch + block is used to fallback to ADSI WinNT provider. #> function Add-GroupMember { @@ -2525,7 +2530,18 @@ function Add-GroupMember $MemberAsPrincipal ) - $Group.Members.Add($MemberAsPrincipal) + try + { + $Group.Members.Add($MemberAsPrincipal) + } + catch + { + Write-Verbose -Message $script:localizedData.PrincipalCollectionAddMethodException + Write-Verbose -Message $_.ToString() + Write-Verbose -Message $script:localizedData.WinNTProviderFallback + [ADSI] $adsiGroup = ("WinNT://$env:COMPUTERNAME/$($Group.Name),group") + $adsiGroup.Add("WinNT://$($MemberAsPrincipal.Sid)") + } } <# diff --git a/source/DSCResources/DSC_xGroupResource/en-US/DSC_xGroupResource.strings.psd1 b/source/DSCResources/DSC_xGroupResource/en-US/DSC_xGroupResource.strings.psd1 index 8674e535..8ebbdd72 100644 --- a/source/DSCResources/DSC_xGroupResource/en-US/DSC_xGroupResource.strings.psd1 +++ b/source/DSCResources/DSC_xGroupResource/en-US/DSC_xGroupResource.strings.psd1 @@ -32,4 +32,6 @@ ConvertFrom-StringData @' SetTargetResourceEndMessage = End executing Set functionality on the group {0}. MembersToIncludeEmpty = MembersToInclude is empty. No group member additions are needed. MembersToExcludeEmpty = MembersToExclude is empty. No group member removals are needed. + PrincipalCollectionAddMethodException = The Add method of the System.DirectoryServices.AccountManagement.PrincipalCollection class has thrown an exception. + WinNTProviderFallback = Falling back to ADSI WinNT provider. '@