diff --git a/CHANGELOG.md b/CHANGELOG.md index 941d6e3214..e5ea22fad6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ * Fix for the MakeDefault property where it wasn't properly setting existing policies to default. FIXES #1648 +* MISC + * Error Handling in Delta Report and removal of Authentication mechanism comparison; + FIXES #1548, #1541 # 1.21.1229.1 diff --git a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 index e0f49b4cb2..8d2e40bc38 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 @@ -376,7 +376,7 @@ function Compare-M365DSCConfigurations Key = $keyName KeyValue = $SourceKeyValue Properties = @(@{ - ParameterName = 'Ensure' + ParameterName = '_IsInConfiguration_' ValueInSource = 'Present' ValueInDestination = 'Absent' }) @@ -390,48 +390,52 @@ function Compare-M365DSCConfigurations # The resource instance exists in both the source and the destination. Compare each property; foreach ($propertyName in $sourceResource.Keys) { - # Needs to be a separate nested if statement otherwise the ReferenceObject an be null and it will error out; - if($null -ne (Compare-Object -ReferenceObject ($sourceResource.$propertyName)` - -DifferenceObject ($destinationResource.$propertyName))) + if ($propertyName -notin @("ResourceName","Credential", "CertificatePath", "CertificatePassword", "TenantId", "ApplicationId", "CertificateThumbprint", "ApplicationSecret")) { - if ($null -eq $drift) + # Needs to be a separate nested if statement otherwise the ReferenceObject an be null and it will error out; + if([System.String]::IsNullOrEmpty($destinationResource.$propertyName) -or (-not [System.String]::IsNullOrEmpty($propertyName) -and + $null -ne (Compare-Object -ReferenceObject ($sourceResource.$propertyName)` + -DifferenceObject ($destinationResource.$propertyName)))) { - $drift = @{ - ResourceName = $sourceResource.ResourceName - Key = $keyname - KeyValue = $SourceKeyValue - Properties = @(@{ - ParameterName = $propertyName - ValueInSource = $sourceResource.$propertyName - ValueInDestination = $destinationResource.$propertyName - }) - } - - if ($destinationResource.Contains("_metadata_$($propertyName)")) + if ($null -eq $drift) { - $Metadata = $destinationResource."_metadata_$($propertyName)" - $Level = $Metadata.Split('|')[0].Replace("### ", "") - $Information = $Metadata.Split('|')[1] - $drift.Properties[0].Add("_Metadata_Level", $Level) - $drift.Properties[0].Add("_Metadata_Info", $Information) - } - } - else - { - $newDrift = @{ - ParameterName = $propertyName - ValueInSource = $sourceResource.$propertyName - ValueInDestination = $destinationResource.$propertyName + $drift = @{ + ResourceName = $sourceResource.ResourceName + Key = $keyname + KeyValue = $SourceKeyValue + Properties = @(@{ + ParameterName = $propertyName + ValueInSource = $sourceResource.$propertyName + ValueInDestination = $destinationResource.$propertyName + }) + } + + if ($destinationResource.Contains("_metadata_$($propertyName)")) + { + $Metadata = $destinationResource."_metadata_$($propertyName)" + $Level = $Metadata.Split('|')[0].Replace("### ", "") + $Information = $Metadata.Split('|')[1] + $drift.Properties[0].Add("_Metadata_Level", $Level) + $drift.Properties[0].Add("_Metadata_Info", $Information) + } } - if ($destinationResource.Contains("_metadata_$($propertyName)")) + else { - $Metadata = $destinationResource."_metadata_$($propertyName)" - $Level = $Metadata.Split('|')[0].Replace("### ", "") - $Information = $Metadata.Split('|')[1] - $newDrift.Add("_Metadata_Level", $Level) - $newDrift.Add("_Metadata_Info", $Information) + $newDrift = @{ + ParameterName = $propertyName + ValueInSource = $sourceResource.$propertyName + ValueInDestination = $destinationResource.$propertyName + } + if ($destinationResource.Contains("_metadata_$($propertyName)")) + { + $Metadata = $destinationResource."_metadata_$($propertyName)" + $Level = $Metadata.Split('|')[0].Replace("### ", "") + $Information = $Metadata.Split('|')[1] + $newDrift.Add("_Metadata_Level", $Level) + $newDrift.Add("_Metadata_Info", $Information) + } + $drift.Properties += $newDrift } - $drift.Properties += $newDrift } } } @@ -440,27 +444,31 @@ function Compare-M365DSCConfigurations # object. By scanning against the destination we will catch properties that are not null on the source but not null in destination; foreach ($propertyName in $destinationResource.Keys) { - if (-not $sourceResource.Contains($propertyName)) + if ($propertyName -notin @("ResourceName", "Credential", "CertificatePath", "CertificatePassword", "TenantId", "ApplicationId", "CertificateThumbprint", "ApplicationSecret")) { - if ($null -eq $drift) + if (-not [System.String]::IsNullOrEmpty($propertyName) -and + -not $sourceResource.Contains($propertyName)) { - $drift = @{ - ResourceName = $sourceResource.ResourceName - Key = $keyName - KeyValue = $SourceKeyValue - Properties = @(@{ - ParameterName = $propertyName - ValueInSource = $null - ValueInDestination = $destinationResource.$propertyName - }) + if ($null -eq $drift) + { + $drift = @{ + ResourceName = $sourceResource.ResourceName + Key = $keyName + KeyValue = $SourceKeyValue + Properties = @(@{ + ParameterName = $propertyName + ValueInSource = $null + ValueInDestination = $destinationResource.$propertyName + }) + } } - } - else - { - $drift.Properties += @{ - ParameterName = $propertyName - ValueInSource = $null - ValueInDestination = $destinationResource.$propertyName + else + { + $drift.Properties += @{ + ParameterName = $propertyName + ValueInSource = $null + ValueInDestination = $destinationResource.$propertyName + } } } } @@ -683,11 +691,11 @@ function New-M365DSCDeltaReport [void]$reportSB.AppendLine("Microsoft365DSC Slogan") [void]$ReportSB.AppendLine("") - [array]$resourcesMissingInSource = $Delta | Where-Object -FilterScript {$_.Properties.ParameterName -eq 'Ensure' -and ` + [array]$resourcesMissingInSource = $Delta | Where-Object -FilterScript {$_.Properties.ParameterName -eq '_IsInConfiguration_' -and ` $_.Properties.ValueInSource -eq 'Absent'} - [array]$resourcesMissingInDestination = $Delta | Where-Object -FilterScript {$_.Properties.ParameterName -eq 'Ensure' -and ` + [array]$resourcesMissingInDestination = $Delta | Where-Object -FilterScript {$_.Properties.ParameterName -eq '_IsInConfiguration_' -and ` $_.Properties.ValueInDestination -eq 'Absent'} - [array]$resourcesInDrift = $Delta | Where-Object -FilterScript {$_.Properties.ParameterName -ne 'Ensure'} + [array]$resourcesInDrift = $Delta | Where-Object -FilterScript {$_.Properties.ParameterName -ne '_IsInConfiguration_'} if ($resourcesMissingInSource.Count -eq 0 -and $resourcesMissingInDestination.Count -eq 0 -and ` $resourcesInDrift.Count -eq 0)