Tested on the Legacy script (V1). I didn't test on the V2 version.
For a workaround, see below.
If a formatting value (be it for color or style) is using accent or other non-ascii characters, then the color or style won't be applied.
Since event log are localized, accented characters can appeared in the report (French in our case).
Given a formatting option below:
$FormattingParameters = @{
Colors = @{
Green = 'ajouté', 'activé' # 'added', 'activated'
}
}
It does not highlight the word:

The issue is not linked to the file encoding, as UTF8-BOM is used and the accent is correctly encoded as we can see in the log:

The issue is related to the way the replace function is actually called:
|
Write-Color @WriteParameters -Text "[i] Preparing template ", "adding", " HTML ", "$($style.Name)", " tag for ", "$value", ' tags...' -Color White, Yellow, White, Yellow, White, Yellow -NoNewLine |
|
$Body = $Body.Replace($value, "<$($style.Name)>$value</$($style.Name)>") |
|
Write-Color -Text "Done" -Color "Green" |
We can see the Replace function is called on the Body variable which contains the HTML body.
Accents (and others non-ascii characters) are usually html-encoded to avoid rendering issue.
We can quickly see this is indeed the case here when looking at the raw HTML output:

The solution would be to html-encode the color/style values before trying to replace them in the HTML body.
Workaround
For a simple workaround, simply drop these two lines before calling Start-ADReporting (assuming the formatting options are in the $FormattingParameters variable):
$FormattingParameters.Colors.clone().Keys | % { $FormattingParameters.Colors[$_] = $FormattingParameters.Colors[$_] | % { [System.Web.HttpUtility]::HtmlEncode([System.Web.HttpUtility]::HtmlDecode($_)) } }
$FormattingParameters.Styles.clone().Keys | % { $FormattingParameters.Styles[$_] = $FormattingParameters.Styles[$_] | % { [System.Web.HttpUtility]::HtmlEncode([System.Web.HttpUtility]::HtmlDecode($_)) } }
It simply iterates over all colors/styles values and html-encode them.
(Note that I left the HtmlDecode in case somebody run these lines multiple time)
With that, the colors and styles are now working 😸

Tested on the Legacy script (V1). I didn't test on the V2 version.
For a workaround, see below.
If a formatting value (be it for color or style) is using accent or other non-ascii characters, then the color or style won't be applied.
Since event log are localized, accented characters can appeared in the report (French in our case).
Given a formatting option below:
It does not highlight the word:

The issue is not linked to the file encoding, as UTF8-BOM is used and the accent is correctly encoded as we can see in the log:

The issue is related to the way the replace function is actually called:
PSWinReporting/Private/PSWinReportingEmails.ps1
Lines 62 to 64 in 36089a8
We can see the
Replacefunction is called on theBodyvariable which contains the HTML body.Accents (and others non-ascii characters) are usually html-encoded to avoid rendering issue.

We can quickly see this is indeed the case here when looking at the raw HTML output:
The solution would be to html-encode the color/style values before trying to replace them in the HTML body.
Workaround
For a simple workaround, simply drop these two lines before calling
Start-ADReporting(assuming the formatting options are in the$FormattingParametersvariable):It simply iterates over all colors/styles values and html-encode them.
(Note that I left the HtmlDecode in case somebody run these lines multiple time)
With that, the colors and styles are now working 😸
