Powershell convertto-html break image in new Outlook with Copilot

Copper Contributor

 

Hello,

 

I create a powershell 7.2 azure automation runbook who use microsoft graph to put some users in Azure groups and activate the new Outlook Experience for Copilot.

 

That part work well.

 

The problem is the confirmation email i send with powershell and microsoft graph with Send-MgUserMail .

 

This email resume the listing of all the users who has been go throught the runbook to get the new Outlook Experience.

 

In the email i show the image of the user (get with mggraph and converted to base64) with somes informations .

 

In Outlook without Copilot and the new experience activated, all the image show OK in the email.

 

In Outlook with the new experience and Copilot, most images are OK but the one who are generated with convertto-html dont show up. 

 

Here the code where i get the image:

 

Try{  Get-MgUserPhotoContent -UserId $u -OutFile "c:\temp\$u.jpg" -ErrorAction stop
$image = Get-ChildItem "c:\temp\$u.jpg" -ErrorAction stop
$ImageBits = [Convert]::ToBase64String((Get-Content $image -AsByteStream))
}
Catch{"No photo found for $u"}
if($image -eq $null){
  $ImageHTML = "<img height=72 width=72 src=data&colon;image/jpg;base64,$($noimagebase64)/>"
}
else{
$ImageHTML = "<img height=72 width=72 src=data&colon;image/jpg;base64,$($ImageBits)/>"
}
if(($getnoe).OneWinNativeOutlookEnabled -eq "True"){
$check = "<img height=25 width=25 src=data&colon;image/png;base64,$($minigreencheck)/>"
}
else{$check ="FALSE"}

 

After that i create an array with the user photo and some informations like the device name et license name

 

  $u | ForEach-Object {
    $userstatus += [pscustomobject]@{
      Photo = $ImageHTML ;
      Name = $username ;
      Email = ($u) -join";";
      Outlook = $check ;
        License = $getlicense.SkuPartNumber -join";";
        UserDevice = $device.DeviceName ;
        Groupe_Policy = $Groupe_Policy ;
    }
  }

 

And at the end i convert that array into HTML table to put in my email

 

$tableuser = $userstatus| ConvertTo-Html -Fragment -As Table | Out-String
$tableuser = [System.Web.HttpUtility]::HtmlDecode($tableuser )

 

So here is the exemple where it work well, we can see the user photo (masked here) and the green check mark as well as the copilot logo at the top.

 

 good.png

 

 

 

And here is in OWA and Outlook with new experience where all image are broken (the one i convertto-html) but the copilot logo at the top is OK. So base64 image is supported in both version.



 

 bad.png

 

 

I know CID can be use to but i already code everything and its work well with most outlook version.

Thank you!

 

0 Replies