dsccommunity / SharePointDsc

The SharePointDsc PowerShell module provides DSC resources that can be used to deploy and manage a SharePoint farm
MIT License
247 stars 107 forks source link

SPCertificateSettings: Unable to set contacts when previously blank #1430

Closed regularroutine closed 6 months ago

regularroutine commented 1 year ago

Problem description

SharePoint Subscription Edition farm without Certificate notification contacts are unable to set them using the SPCertificateSettings resource: Cannot bind argument to parameter 'DifferenceObject' because it is null

Verbose logs

VERBOSE: [SERVERNAME]:                            [[SPCertificateSettings]CertificateSettings] Performing the operation "Se
t-SPCertificateSettings" on target "certificate management default settings".
VERBOSE: [SERVERNAME]:                            [[SPCertificateSettings]CertificateSettings] Leaving ProcessRecord Method
 of Set-SPCertificateSettings.
VERBOSE: [SERVERNAME]:                            [[SPCertificateSettings]CertificateSettings] Leaving EndProcessing Method
 of Set-SPCertificateSettings.
VERBOSE: [SERVERNAME]:                            [[SPCertificateSettings]CertificateSettings] Checking Certificate Notific
ation Contacts
VERBOSE: [SERVERNAME]:                            [[SPCertificateSettings]CertificateSettings] Leaving BeginProcessing Meth
od of Get-SPCertificateNotificationContact.
VERBOSE: [SERVERNAME]:                            [[SPCertificateSettings]CertificateSettings] Leaving ProcessRecord Method
 of Get-SPCertificateNotificationContact.
VERBOSE: [SERVERNAME]:                            [[SPCertificateSettings]CertificateSettings] Leaving EndProcessing Method
 of Get-SPCertificateNotificationContact.
VERBOSE: [SERVERNAME]: LCM:  [ End    Set      ]  [[SPCertificateSettings]CertificateSettings]  in 0.5860 seconds.
PowerShell DSC resource MSFT_SPCertificateSettings  failed to execute Set-TargetResource functionality with error message: 
Cannot bind argument to parameter 'DifferenceObject' because it is null. 
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

DSC configuration

# Set Certificate Notification Contacts
SPCertificateSettings CertificateSettings
{
   IsSingleInstance                = 'Yes'
   CertificateNotificationContacts = $ConfigurationData.NonNodeData.CertificateNotificationContacts
   PsDscRunAsCredential            = $Credsinstallaccount
   DependsOn                       = "[SPFarm]ConfigureSPFarm" 
}

Suggested solution

Problem is probably due to "C:\Program Files\WindowsPowerShell\Modules\SharePointDSC\5.3.0\DSCResources\MSFT_SPCertificateSettings\MSFT_SPCertificateSettings.psm1" and this compare: $diffs = Compare-Object -ReferenceObject $desiredContacts -DifferenceObject $currentContacts

Perhaps having a check for null value before this and only going to the above row if there are available contacts.

SharePoint version and build

SharePoint Subscription Edition May 2023

Operating system the target node is running

Server 2022

PowerShell version and build the target node is running

Name                           Value                                           
----                           -----                                           
PSVersion                      5.1.20348.1366                                  
PSEdition                      Desktop                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                         
BuildVersion                   10.0.20348.1366                                 
CLRVersion                     4.0.30319.42000                                 
WSManStackVersion              3.0                                             
PSRemotingProtocolVersion      2.3                                             
SerializationVersion           1.1.0.1

SharePointDsc version

SharePointDSC 5.3.0