December 31st, 2015

PowerTip: Use Here-Strings with PowerShell

Doctor Scripto
Scripter

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! 
"@

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.