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