Creating multi-line email body in powershell

Question:

I keep getting error when I am trying to implement multiple line email body. I am suspecting bad syntax. Can’t find any example online. Any suggestions?

Error: Unexpected token 'EmployeeName"] to $AccountExpire"' in expression or statement.

Answer:

You need to escape those array index operations with a subexpression ($()):

Same goes for multi-line strings (or here-strings as they’re formally called):


Personally, I’d go for a multi-line template and use the -f format operator to fill in the values:

When using -f, you can also format different types of data, so if $NewDate is a [DateTime] object, you could control formatting for that inside the template, eg.:

which would produce:

(assuming you did this a five to 3 in the afternoon)

Source:

Creating multi-line email body in powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply