0
0
PowerShellscripting~5 mins

String type and interpolation in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a string in PowerShell?
A string is a sequence of characters used to represent text. In PowerShell, strings are enclosed in single ('') or double ("") quotes.
Click to reveal answer
beginner
How do single quotes and double quotes differ in PowerShell strings?
Single quotes ('') create literal strings where variables are not expanded. Double quotes ("") allow variable interpolation, meaning variables inside the string are replaced with their values.
Click to reveal answer
beginner
Example: What will this output? <br>
$name = 'Sam'
Write-Output 'Hello, $name'
It will output: Hello, $name <br>Because single quotes do not expand variables, the output shows the variable name literally.
Click to reveal answer
beginner
Example: What will this output? <br>
$name = 'Sam'
Write-Output "Hello, $name"
It will output: Hello, Sam <br>Because double quotes allow variable interpolation, the variable $name is replaced with its value.
Click to reveal answer
intermediate
How can you include a literal dollar sign ($) in a double-quoted string without triggering variable interpolation?
Use the backtick (`) escape character before the dollar sign, like this: "Price is `$5". This prints: Price is $5.
Click to reveal answer
Which quotes allow variable interpolation in PowerShell?
ADouble quotes ("")
BSingle quotes ('')
CBackticks (`)
DNo quotes allow interpolation
What will this output? <br>
$var = 10
Write-Output 'Value is $var'
AValue is $var
BValue is 10
CError
DValue is
How do you escape a dollar sign in a double-quoted string?
AUse single quotes instead
BUse a backtick before $
CUse a backslash before $
DNo need to escape
What type of string is this? <br>
'Hello, World!'
AInterpolated string
BHere-string
CLiteral string
DCommand string
Which is true about double-quoted strings in PowerShell?
AThey do not allow variable expansion
BThey are deprecated
CThey are used only for commands
DThey allow variable expansion
Explain the difference between single-quoted and double-quoted strings in PowerShell.
Think about how variables behave inside each type of quotes.
You got /4 concepts.
    How do you include a literal dollar sign ($) in a double-quoted string without triggering variable interpolation?
    Remember the escape character in PowerShell.
    You got /3 concepts.