Skip to content

Commit

Permalink
Fixes issue microsoft#2236
Browse files Browse the repository at this point in the history
  • Loading branch information
NikCharlebois committed Oct 17, 2022
1 parent c14f7dc commit 20f8570
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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
}
}
Expand All @@ -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"))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 20f8570

Please sign in to comment.