Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

MSFT_GroupResource: Fix for the issue #82 #198

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change log for PsDscResources

## Unreleased
* Group
* Workaround added for the [Issue #82](https://github.com/PowerShell/PSDscResources/issues/82)
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.

## 2.12.0.0

Expand Down
20 changes: 18 additions & 2 deletions DscResources/MSFT_GroupResource/MSFT_GroupResource.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2487,13 +2487,18 @@ function Clear-GroupMember
<#
.SYNOPSIS
Adds the specified member to the specified group.
This is a wrapper function for testing purposes.

.PARAMETER Group
The group to add the member to.

.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
{
Expand All @@ -2511,7 +2516,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)")
}
}

<#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,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.
'@