SharePointDsc: SPFarmAdministrators: Resource fails with error message: An item with the same key has already been added

Error Message: PowerShell DSC resource MSFT_SPFarmAdministrators failed to execute Set-TargetResource functionality with error message: An item with the same key has already been added

Details of the scenario you tried and the problem that is occurring Just added one AD-group to Members in resource SPFarmAdministrators

Verbose logs showing the problem Suggested solution to the issue Case insensitive search of groups and accounts before adding them to Lists and Dictionaries

The DSC configuration that is used to reproduce the issue (as detailed as possible) PowerShell DSC:

SPFarmAdministrators 'FarmAdministrators' {
    PsDscRunAsCredential = $SetupCredential
    IsSingleInstance = 'Yes'
    Members = @($ConfigurationData.NonNodeData.SharePoint.AdministratorsGroup) +
                        @($ConfigurationData.NonNodeData.SharePoint.MonitorsGroup) | ? { $_ }
    DependsOn = @('[SPFarm]Farm')
}

MOF:

instance of MSFT_SPFarmAdministrators as $MSFT_SPFarmAdministrators1ref
{
    ResourceID = "[SPFarmAdministrators]FarmAdministrators";
    PsDscRunAsCredential = $MSFT_Credential29ref;
    Members = {
        "\SpIntAdmins"
    };
    SourceInfo = "C:\Users\JhonDoe\repos\Source\DSC\~Config\SPFarmDSC.ps1::785::13::SPFarmAdministrators";
    IsSingleInstance = "Yes";
    ModuleName = "SharePointDsc";
    ModuleVersion = "4.6.0";

    DependsOn = {

        "[SPFarm]Farm"
    };
    ConfigurationName = "SPFarmDSC";
};

The operating system the target node is running

OsName : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture : 64-bit
WindowsBuildLabEx : 14393.3750.amd64fre.rs1_release.200601-1853
OsLanguage : en-US
OsMuiLanguages : {en-US}

Version of SharePoint that is used (e.g. SharePoint 2016) SharePoint 2016

Version and build of PowerShell the target node is running


PSVersion 5.1.14393.3471
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3471
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Version of the DSC module that was used ModuleVersion = “4.6.0”;

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (14 by maintainers)

Commits related to this issue

Most upvoted comments

It is a combination of both changes that does the trick. The Import-SPPoweShellSnapIn.ps1 is required for the ReverseDsc integration, but in some cases that also threw the same error. That is why we added the two lines at the top of each resource.

As it turns out, here there are also scenarios where the error is thrown as you encountered.

By implemented both changes, we make sure the snap-in is only loaded when the Export cmdlet is called.

I will include these fixes in my next Bugfix PR!

Hi @luigilink, the issue here is that SharePoint is still using snapins (to be changed in SharePoint Server Subscription Edition!!!).

So far I do not have a solution yet, but might have an idea how to resolve this issue. Have to find some time to test if this will work.

The workaround you are describing will work

Hi @luigilink, that is correct. With the addition of native ReverseDsc support we made an update to load the snapin a certain way. We needed that to prevent the exact same error to be thrown during a config export.

It now looks like that because of this we are hitting the same issue in these situations. Before I was unable to replicate, but yesterday I have been working on a new resource which I just started testing. During these tests I am hitting the same issue. I have a clue where this is coming from, now just figuring out how to solve it.

Will keep all of you posted!