Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-M365DSCDeltaReport returns no delta information #1970

Closed
yoinuma opened this issue May 26, 2022 · 6 comments · Fixed by #2130 or #2143
Closed

New-M365DSCDeltaReport returns no delta information #1970

yoinuma opened this issue May 26, 2022 · 6 comments · Fixed by #2130 or #2143
Labels
Bug Something isn't working Core Engine

Comments

@yoinuma
Copy link

yoinuma commented May 26, 2022

Details of the scenario you tried and the problem that is occurring

Comparing the files output by Export-M365DSCConfiguration for two different SPO tenant level settings (CommentsOnSitePagesDisabled, SPOHubSite, LegacyAuthProtocolsEnabled, etc), the New-M365DSCDeltaReport command does not output any difference information.

New-M365DSCDeltaReport -Source "C:\temp\dsc\20220526Config.ps1" -Destination "C:\temp\dsc\InitialConfig.ps1" -OutputPath "C:\temp\dsc\output.html"
image
image

Verbose logs showing the problem

Suggested solution to the issue

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

# insert configuration here

The operating system the target node is running

Version of the DSC module that was used ('dev' if using current dev branch)

1.22.525.1
image

@ghost
Copy link

ghost commented May 26, 2022

I am also getting similar issues.
Blueprint assessments - been struggling for a few versions now.
Have found some issues get fixed by closing the powershell window and re-opening, but as yet a Assert or delta reports do not work.

These are the errors im getting


Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.22.525.1\modules\M365DSCReport.psm1:833 char:26
+     if ((Test-Path -Path $OutputPath) -eq $false)
+                          ~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Test-Path], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Test
   PathCommand

Exception calling "IndexOf" with "2" argument(s): "Index was out of range. Must be non-negative and less than the size
of the collection.
Parameter name: startIndex"
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.22.525.1\modules\M365DSCReport.psm1:475 char:9
+         $endPosition = $fileContent.IndexOf("`r", $startPosition)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

Exception calling "Remove" with "2" argument(s): "StartIndex cannot be less than zero.
Parameter name: startIndex"
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.22.525.1\modules\M365DSCReport.psm1:476 char:9
+         $fileContent = $fileContent.Remove($startPosition, $endPositi ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

<h1>Blueprint Assessment Report</h1>
<html><head><meta charset='utf-8'><title>Microsoft365DSC - Blueprint Assessment Report</title></head><body>
<div style='width:100%;text-align:center;'>
<img src='http://Microsoft365DSC.com/Images/Promo.png' alt='Microsoft365DSC Slogan' width='500' />
</div>
<p><strong>No discrepancies have been found!</strong></p>
</body></html>


I want to compare a dev environment after making changes, and also against a blueprint thats created.
If for some reason i have multiple compliance policies etc, it should match and compare all of them against the template surely?

@andikrueger
Copy link
Collaborator

Exception calling "IndexOf" with "2" argument(s): "Index was out of range. Must be non-negative and less than the size
of the collection.
Parameter name: startIndex"
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.22.525.1\modules\M365DSCReport.psm1:475 char:9
+         $endPosition = $fileContent.IndexOf("`r", $startPosition)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

Exception calling "Remove" with "2" argument(s): "StartIndex cannot be less than zero.
Parameter name: startIndex"
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.22.525.1\modules\M365DSCReport.psm1:476 char:9
+         $fileContent = $fileContent.Remove($startPosition, $endPositi ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

These errors are related to configurations that do not hold proper information about the Microsoft365DSC Version used for the export/configuration.

Please make sure to have the following line with -ModuleVersion within your configuration/blueprint

Import-DscResource -ModuleName 'Microsoft365DSC' -ModuleVersion '1.22.202.1'

$OutputPath is a mandatory parameter. Currently the parameter misses this appropriate annotation.

@mpiederiet
Copy link
Contributor

Hi Andi,

I don't fully agree with your statement of the 'ModuleVersion' being required, because in all the functions in M365DSC that use ConvertTo-DSCObject these are stripped from the file content before parsing the DSC file (effectively breaking ConvertTo-DSCObject in PS7)

To illustrate what I mean, please see these lines

$fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition)

$fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition)

$fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition)

$fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition)

$fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition)

$fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition)

This modification of the DSC content breaks parsing the DSC object in PowerShell 7. To summarize, here are the results of my tests:

ConvertTo-DSCObject, file content WITH ModuleVersion
PS5: works
PS7: works

ConvertTo-DSCObject, file content WITHOUT ModuleVersion
PS5: works
PS7: does not work, results in empty DSCobject

So, in general I think it's better to NOT strip the ModuleVersion from the FileContent so it will work in all PS versions...

@NikCharlebois I see you've added these modifications in 87bf79f
any idea on why this was added?

@andikrueger
Copy link
Collaborator

That change was made to allow the conversion of configurations regardless of microsoft365dsc module version available on the system.

could you verify that you do not have multiple versions of m365dsc installed within ps7? Please have a look at the comments within #2120.

@NikCharlebois
Copy link
Collaborator

Andi is correct, the ModuleVersion was removed to ensure you could compare two configurations that were using a different version of the module. Otherwise, you would have to manually update the configuration to point to the correct installed version every time an assessment was being performed. I am working on a fix that will ensure the ModuleVersion is found before attempting to strip it out. I was able to confirm that this works with both PoSh 5 and 7.1 if the module version is not specified in the files.

NikCharlebois added a commit to NikCharlebois/Microsoft365DSC that referenced this issue Jul 22, 2022
@mpiederiet
Copy link
Contributor

Oops, my bad. Removing the old Microsoft365DSC versions in PS7 fixed it for me. I assumed this had to do with the difference in PowerShell versions, but just now I learned that only one version of the Microsoft365DSC module needs to be installed... Thanks for having a look @andikrueger and @NikCharlebois!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Core Engine
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants