Using here-strings

Until now, you have only seen single-line strings in this book. PowerShell has a so-called here-string that spans multiple lines. You use @" or @' to start the here-string and "@ or '@ to finish the here-string. The @"or @' must be at the end of a line and the "@ or '@ must be at the beginning of the line that terminates the here-string. As in single-line strings, variables and subexpressions are expanded in double-quoted here-strings and are not expanded in single-quoted here-strings.

The following command creates a here-string that spans two lines and puts the here-string in the variable $s:

PowerCLI C:\> $s = @"
>> Learning PowerCLI
>> is a lot of fun!
>> "@
>> $s
>>
Learning PowerCLI
is a lot of fun!

Get Learning PowerCLI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.