Skip to content

SPOSharingSettings: Connection errors cause false positive drift detection #6677

@SNikalaichyk

Description

@SNikalaichyk

Description of the issue

Issue

SPOSharingSettings reports false drift when Get-TargetResource encounters intermittent connection errors but fails to handle them properly, returning Ensure = "Absent" instead of failing cleanly.

Error Details:

Error retrieving data:
{ Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. }
at Get-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.910.2\DscResources\MSFT_SPOSharingSettings\MSFT_SPOSharingSettings.psm1: line 178
at Test-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.910.2\DscResources\MSFT_SPOSharingSettings\MSFT_SPOSharingSettings.psm1: line 694

Configuration Drift Event:

<ConfigurationDrift Source="MSFT_SPOSharingSettings" TenantId="contoso.onmicrosoft.com">
    <ParametersNotInDesiredState>
        <Param Name="Ensure">
            <CurrentValue>Absent</CurrentValue>
            <DesiredValue>Present</DesiredValue>
        </Param>
    </ParametersNotInDesiredState>
</ConfigurationDrift>

Root Cause

The centralized Test-M365DSCTargetResource function contains unprotected calls to individual resource Get-TargetResource functions, causing systematic false drift detection across all resources that utilize this shared function. When any resource experiences connection errors or API failures, the function fails to distinguish between legitimate configuration drift and retrieval failures, triggering unnecessary remediation cycles that can affect properly configured resources.

$CurrentValues = & MSFT_$ResourceName\Get-TargetResource @DesiredValues

Permalink

Impact

  • False drift alerts when intermittent connection issues occur
  • Unnecessary remediation attempts on properly configured resources
  • Cannot distinguish legitimate drift from retrieval failures

Solution

  1. Protect the Get-TargetResource call in Test-M365DSCTargetResource
  2. Return an error instead of false drift when current state retrieval fails

Microsoft 365 DSC Version

v1.25.910.2 (and later)

Which workloads are affected

SharePoint Online

The DSC configuration

Verbose logs showing the problem

Environment Information + PowerShell Version

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions