Graph API User.SendMail Shows System.Object[]

When sending emails using the Graph API PowerShell module with a variable in the Body property, the email body shows System.Object[].

In the example code, I’m using Graph PowerShell to send an email

$params = @{
          message = @{
          subject = Message Subject" 
          body = @{
              contentType = "text"
              content = $output                                   
                }
                 toRecipients = @(
                                @{
                                  emailAddress = @{
                                  address = "Email Here"
                                   }
                             }
                                 )
                                     
         }
     saveToSentItems = "false"
                }
Send-MgUserMail -UserId $userId -BodyParameter $params

Solution

The reason the Body property shows System.Object[] is because it’s expected to receive a string.

To fix the issue, add | out-string to the value in the content property, as shown below.

content = $output  | Out-String 





Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.