[Solved] Send-MailMessage : Cannot convert ‘System.Collections.ArrayList’

You may get the following error message:

Send-MailMessage :
Cannot convert 'System.Collections.ArrayList' to the type 'System.String' required by parameter 'Body'.
Specified method is not supported.

The reason

This error message is really explicit: The body of the mail must be a string and you are giving an array as input.

The solution

Unfortunately, you cannot use the ToString method.

$Body = $MyArray.ToString()

In this case, all you will get is a mail with only the System.Collections.ArrayList expression.
In order to convert the body to a string, you must use the Out-String cmdlet.
For example:

$Body = $MyArray | Out-String

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s