Running "Email" as part of the PSWriteHTML functionality

Product: PowerShell Universal
Version: 1.4.6

I am using the PSWriteHTML module to send emails, with nicely formatted tables. For some reason the Email feature is not working when run through PSU. Running the same script from a PS console on the PSU server is running without problems. The error thrown is

Feb 14, 2022 8:40 AM Invoke-Command: C:\Program Files\PowerShell\Modules\PSWriteHTML\0.0.168\PSWriteHTML.psm1:12387

Feb 14, 2022 8:40 AM Line |

Feb 14, 2022 8:40 AM 12387 | [Array] $EmailParameters = Invoke-Command -ScriptBlock $Email

Feb 14, 2022 8:40 AM | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Feb 14, 2022 8:40 AM | Object reference not set to an instance of an object.

I can reproduce this by using Invoke-Command.

Invoke-Command -ScriptBlock { Get-Process }

Are you using Invoke-Command or is that part of the PSWriteHTML module?

I am not using invoke-command. All is builtin the PSWriteHTML module. I call the Email function with switches as the example here shows

It looks like a problem with our custom host in scripts but doesn’t manifest in APIs. You could create an API and then call it from the script with Invoke-RestMethod to work around it.

I’m running into the same problem inside of PowerShell Universal when using the PSWriteHTML Email Function. Is there another way around this? I’ve tried using Send-MailMessage in the PS5.1 Environment but seem to be having the same problem.