PowerTip: Use Here-Strings with PowerShell

Doctor Scripto

Summary: Learn the basic use of a here-string in Windows PowerShell.

Hey, Scripting Guy! Question What is a here-string and how do I use it?

Hey, Scripting Guy! AnswerIn PowerShell, you can use here-strings to declare blocks of text. They’re declared just like regular strings except they have an @ on each end. Instead of being limited to one line, you can declare an entire block or a multiple line string. Here-strings are also useful for making a string composed of the text to execute a command. Try these examples:

$String1 = @" 
Get-ChildItem c:\temp 
"@

$String2 = @" 
This is some
multiple line 
text! 
"@

0 comments

Discussion is closed.

Feedback usabilla icon