diff --git a/CHANGELOG.md b/CHANGELOG.md index 76ebfb2c71..31740dabaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ * MISC * Added support for filtering resources instances at extraction time. FIXES [#1691](https://github.com/microsoft/Microsoft365DSC/issues/1691) + * REPORT: Fixed an issue where if the ModuleVersion was not specified, that the file would fail to properly get parsed. + FIXES [#1970](https://github.com/microsoft/Microsoft365DSC/issues/1970) # 1.22.720.1 diff --git a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 index bf03ab9723..f9f901809f 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 @@ -472,16 +472,28 @@ function Compare-M365DSCConfigurations { $fileContent = Get-Content $Source -Raw $startPosition = $fileContent.IndexOf(" -ModuleVersion") - $endPosition = $fileContent.IndexOf("`r", $startPosition) - $fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition) + if ($startPosition -ge 0) + { + $endPosition = $fileContent.IndexOf("`r", $startPosition) + if ($endPosition -gt $startPosition) + { + $fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition) + } + } [Array] $SourceObject = ConvertTo-DSCObject -Content $fileContent } if (-not $DestinationObject) { $fileContent = Get-Content $Destination -Raw $startPosition = $fileContent.IndexOf(" -ModuleVersion") - $endPosition = $fileContent.IndexOf("`r", $startPosition) - $fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition) + if ($startPosition -ge 0) + { + $endPosition = $fileContent.IndexOf("`r", $startPosition) + if ($endPosition -gt $startPosition) + { + $fileContent = $fileContent.Remove($startPosition, $endPosition - $startPosition) + } + } [Array] $DestinationObject = ConvertTo-DSCObject -Content $FileContent }