Powershell : Comments string

   

Written by:

Special characters

Special characters are used to format/position string output.

   `0  Null
   `a  Alert bell/beep
   `b  Backspace
   `e  Escape (added in PowerShell 6)
   `f  Form feed (use with printer output)
   `n  New line
   `r  Carriage return
 `r`n  Carriage return + New line
   `t  Horizontal tab
 `u{x} An escape sequence of Unicode  (added in PowerShell 6)
   `v  Vertical tab (use with printer output)
#The `r (carriage return) is ignored in PowerShell (ISE) Integrated Scripting Environment host application console, it does work in a PowerShell console session.

The `r (carriage return) is ignored in PowerShell (ISE) Integrated Scripting Environment host application console, it does work in a PowerShell console session.

Special parsing tokens:

— Treat the remaining values as arguments not parameters.

–% Stop parsing anything that follows. See examples below.

Using the Escape character to avoid special meaning. “ To avoid using a Grave-accent as the escape character `# To avoid using # to create a comment `’ To avoid using ‘ to delimit a string `” To avoid using ” to delimit a string

Concatenating Strings

# Specify the .value property and concatenate that with + to get the desired result:
PS C:\> "aaa " + $drive.value + " bbb"
aaa C: bbb

# Alternatively use the $( ) SubExpression operator:
PS C:\> "aaa $($drive.value) bbb"
aaa C: bbb

Here strings

A here string is a single-quoted or double-quoted string which can span multiple lines.
Variables and Expressions in single-quoted strings are not evaluated.

All the lines in a here-string are interpreted as strings, even though they are not enclosed in quotation marks.

$myHereString = @'
some text with "quotes" and variable names $printthis
some plain text
and the children's toys
'@

#If the above were a single quoted string, the ' in children's would need to be escaped.
#If it was a double quoted string, you'd need to escape the instances of " and you'd need to escape the $ if you didn’t want variable expansion.

$anotherHereString = @"
The value of `$var is $var
some more text
"@

#Inside a here-string, double and single quotes are not special but quoted literally, all line breaks are preserved.

#The @ character is also used to create arrays, create hash tables and as a splat operator.

#EXAMPLE 
    $MsgLineFeed = @"
    User Folder founded
    $($focusfolder.FullName)
    the permissions granted are $dataColl
    be aware of the need to warn authorised users

"@

Leave a comment