Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

New-M365DSCDeltaReport fails when PSDesiredStateConfiguration module is not explicitly imported

Open RosalindHook opened this issue 7 months ago • 1 comments

Description of the issue

When running New-M365DSCDeltaReport in isolation (not immediately after an export operation), the command fails due to missing PSDesiredStateConfiguration module dependencies. This appears to be a version compatibility issue between PowerShell 5.1 and the module version being referenced.

Reproduction steps:

  • Open a fresh PowerShell 5.1 session
  • Run New-M365DSCDeltaReport with valid source and destination parameters
  • Observe the error related to PSDesiredStateConfiguration module

Current Workaround Adding the following line before running the delta report resolves the issue: import-module "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration" Additional Context The issue only occurs when running the delta report command in isolation When running New-M365DSCDeltaReport immediately after Export-M365DSCConfiguration in the same session, the error doesn't occur (presumably because the export command loads the correct version of the required dependencies) This appears to be a version compatibility issue rather than a missing module issue.

The issue appears to be that New-M365DSCDeltaReport is attempting to use the PowerShell 6.1 version of the PSDesiredStateConfiguration module when running in PowerShell 5.1. When following the error's suggestion to import the module with Import-Module PSDesiredStateConfiguration -Force, it results in an error about requiring PowerShell 6.

The workaround explicitly imports the PowerShell 5.1 compatible version of the module from the Windows system directory, which allows the command to execute successfully.

Microsoft 365 DSC Version

Microsoft365DSC 1.25.514.1

Which workloads are affected

Exchange Online, Intune, Planner, Teams, SharePoint Online, Office 365 Admin, Azure Active Directory (Entra ID)

The DSC configuration

# This minimal script reproduces the PSDesiredStateConfiguration module loading issue - affects all workloads

# Define paths to existing configuration files for comparison
$sourceConfigPath = "C:\Path\To\Source\Configuration.ps1"
$destinationConfigPath = "C:\Path\To\Destination\Configuration.ps1" 
$outputPath = "C:\Path\To\Output\DeltaReport.json"

# Attempt to generate delta report without explicitly loading the module
# This will fail with the module loading error
try {
    New-M365DSCDeltaReport -Source $sourceConfigPath -Destination $destinationConfigPath -Type 'JSON' -OutputPath $outputPath
}
catch {
    Write-Host "Error occurred: $_"
}

# With the workaround, it succeeds:
# import-module "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration"
# New-M365DSCDeltaReport -Source $sourceConfigPath -Destination $destinationConfigPath -Type 'JSON' -OutputPath $outputPath

Verbose logs showing the problem

import-module "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration"
Error Details
Import-Module : Could not load file or assembly 'file:///C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\Microsoft.Windows.DSC.CoreConfProviders' or one of its dependencies. The system cannot find the file specified.
At line:1 char:1
+ Import-Module PSDesiredStateConfiguration -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

Environment Information + PowerShell Version

Microsoft 365 DSC Version: DEV / 1.25.514.1
PowerShell Version: 5.1
Operating System: Windows (specific details can be provided if needed)

RosalindHook avatar May 27 '25 15:05 RosalindHook

This issue appears because you most likely have installed PSDesiredStateConfiguration in the Windows PowerShell 5.1 version and not in PowerShell 7. Please uninstall it from Windows PowerShell and reinstall it in PowerShell 7.

FabienTschanz avatar Jun 04 '25 20:06 FabienTschanz

@RosalindHook Any updates? Otherwise we will close the issue.

FabienTschanz avatar Jun 30 '25 14:06 FabienTschanz

I haven't really resolved it using the suggestion above, as we are working in Powershell 5.1, not PowerShell 7, but I've got a workaround as I mentioned above by adding the following line before running the delta report: import-module "C:\Windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration"

It's more for your information really as seems strange that running the delta report command in isolation causes this issue.

RosalindHook avatar Jun 30 '25 14:06 RosalindHook

Hmm, then that's really strange. But if you found a workaround, I'll therefore close the issue. You might try it on another computer, it could be that some modules are corrupt.

FabienTschanz avatar Jul 01 '25 21:07 FabienTschanz