From 20f857047a4f3ba4973fe3fbf08a35f9f022fb83 Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Mon, 17 Oct 2022 08:20:55 -0400 Subject: [PATCH] Fixes issue #2236 --- CHANGELOG.md | 2 ++ .../MSFT_SCSensitivityLabel.psm1 | 10 ++++++---- Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 | 11 +++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3724827091..86389c98cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * Added support to register, list and remove custom notification endpoints. * Fixes issue with delta report where wrong primary key was detected. FIXES [#2008](https://github.com/microsoft/Microsoft365DSC/issues/2008) + * Fixed an issue where the log engine was throwing an error when trying to write to the event log from an Azure runbook. + FIXES [#2236](https://github.com/microsoft/Microsoft365DSC/issues/2236) # 1.22.1012.1 diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_SCSensitivityLabel/MSFT_SCSensitivityLabel.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_SCSensitivityLabel/MSFT_SCSensitivityLabel.psm1 index 9a201072d7..6af6eb8acd 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_SCSensitivityLabel/MSFT_SCSensitivityLabel.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_SCSensitivityLabel/MSFT_SCSensitivityLabel.psm1 @@ -591,6 +591,7 @@ function Set-TargetResource if (('Present' -eq $Ensure) -and ('Absent' -eq $label.Ensure)) { + Write-Verbose -Message "Label {$Name} doesn't already exist, creating it from the Set-TargetResource function." $CreationParams = $PSBoundParameters if ($PSBoundParameters.ContainsKey("AdvancedSettings")) @@ -610,15 +611,15 @@ function Set-TargetResource $CreationParams.Remove("Priority") $CreationParams.Remove("Disabled") - Write-Verbose "Creating new Sensitivity label $Name calling the New-Label cmdlet." - try { + Write-Verbose -Message "Creating Label {$Name}" New-Label @CreationParams ## Can't set priority until label created if ($PSBoundParameters.ContainsKey("Priority")) { Start-Sleep 5 + Write-Verbose -Message "Updating the priority for newly created label {$Name}" Set-label -Identity $Name -priority $Priority } } @@ -629,6 +630,7 @@ function Set-TargetResource } elseif (('Present' -eq $Ensure) -and ('Present' -eq $label.Ensure)) { + Write-Verbose -Message "Label {$Name} already exist, updating it from the Set-TargetResource function." $SetParams = $PSBoundParameters if ($PSBoundParameters.ContainsKey("AdvancedSettings")) @@ -897,7 +899,7 @@ function Test-TargetResource $ValuesToCheck.Remove('LocaleSettings') | Out-Null $ValuesToCheck.Remove('Disabled') | Out-Null - if ($null -ne $AdvancedSettings) + if ($null -ne $AdvancedSettings -and $null -ne $CurrentValues.AdvancedSettings) { $TestAdvancedSettings = Test-AdvancedSettings -DesiredProperty $AdvancedSettings -CurrentProperty $CurrentValues.AdvancedSettings if ($false -eq $TestAdvancedSettings) @@ -906,7 +908,7 @@ function Test-TargetResource } } - if ($null -ne $LocaleSettings) + if ($null -ne $LocaleSettings -and $null -ne $CurrentValues.LocaleSettings) { $localeSettingsSame = Test-LocaleSettings -DesiredProperty $LocaleSettings -CurrentProperty $CurrentValues.LocaleSettings if ($false -eq $localeSettingsSame) diff --git a/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 index 33f89b439a..ac07ce6313 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 @@ -139,8 +139,15 @@ function Add-M365DSCEvent $message = $message.Substring(0, 32766) } - Write-EventLog -LogName $LogName -Source $Source ` - -EventId $EventID -Message $Message -EntryType $EntryType + try + { + Write-EventLog -LogName $LogName -Source $Source ` + -EventId $EventID -Message $Message -EntryType $EntryType -ErrorAction Stop + } + catch + { + Write-Verbose $_ + } } catch {