string and not a string

The ‘preferred’ way to send email to several people from powershell is to use the send-mailmessage cmdlet.  In our environment, the server needs to be identified as an acceptable server (that is done in a group in the BigIP local traffic manager) else the traffic is not replayed to the SMTP server.  But anyway….

-to switch takes an email address.  -cc and -bcc of course allow more folks to get the message, but to send the email to multiple recipients, you can put the email addresses into an array.  The ‘comma’ operator is the array constructor so”

$emailaddresses = “”,”” ought to work.  Nope.  Wrong format.

Array, huh?

[array]$emailaddresses = “”,”” ought to work.  Nope, complains about a string


[string]$emailaddresses = “”,”” ought to work.  Nope, complains about an object

finally, got a google search hit and found that

[string[]]$emailaddresses = “”,”” ought to work.  It does.

$emailaddresses|gm and $emailaddresses.gettype() both allowed me to see objects and strings, but something about powershell wanted, in this case, an explicit cast to string array.  Problem solved, heading for the next problem.

This entry was posted in Uncategorized. Bookmark the permalink.