When I do enter this in powershell Console
$test=@' Test Test'@
And do enter several times, it keeps printing
>>
So I can never finish command.
What to do ?
A multiline string is a string whose value exceeds beyond one line. In that, the string should be enclosed within a here-string(@””@). Newline or carriage return value can also be used to create a multiline string. Multiline string can also be defined by using a line break within double-quotes.
In PowerShell multiline command can be easily created using ` (backtick character) to split long or single line command into multiline statements. Backtick (`) character is used as escape character, it basically escape the newline character and results in line continuation.
You can create a variable by simply assigning it a value. For example, the command $var4 = “variableexample” creates a variable named $var4 and assigns it a string value. The double quotes (” “) indicate that a string value is being assigned to the variable.
Use triple quotes to create a multiline string It is the simplest method to let a long string split into different lines. You will need to enclose it with a pair of Triple quotes, one at the start and second in the end. Anything inside the enclosing Triple quotes will become part of one multiline string.
'@
should be first thing in the line or it is considered to be just a part of the string.
$test=@' Test Test '@
This approach also works with @"
/"@
As per the section on maximum line length in The PowerShell Best Practices and Style Guide, I would suggest “splatting” the string, like this:
$myStr = ("The family of Dashwood had long been settled in Sussex. Their estate was " + "large, and their residence was at Norland Park, in the centre of their " + "property, where, for many generations, they had lived in so respectable " + "a manner as to engage the general good opinion of their surrounding " + "acquaintance.")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With