question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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”;

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
ykuijscommented, Oct 7, 2021

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!

1reaction
ykuijscommented, Sep 7, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

SPFarmAdministrators fails with "An item with the same key ...
Error Message : PowerShell DSC resource MSFT_SPFarmAdministrators failed ... error message: An item with the same key has already been added ...
Read more >
Error "An item with the same key has already been added"
This article helps to fix the error "An item with the same key has already been added". Applies to: Windows Server 2012 R2...
Read more >
An item with the same key has already been added
I get this error whenever I submit the form also the action method is not being called because of this: An item with...
Read more >
An item with the same key has already been added.
I'm trying to create a new VM using the command: get-vmhost [esx_server_name] | new-vm -name [vm_name] and get the following error: New-VM :...
Read more >
AFElement.FindElement returns 'An item with the same key ...
FindElement(PISystem, GUID) and it is returning the error. "Unexpected Server error: 'An item with the same key has already been added.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found