CompTIA PenTest+ 2025 – 400 Free Practice Questions to Pass the Exam

Question: 1 / 400

Which symbol is necessary for variable assignment in PowerShell?

my_str$ = "Hello, World!"

$my_str = "Hello, World!"

In PowerShell, the variable assignment requires the use of the dollar sign ($) followed by the variable name. The correct format for assigning a string value to a variable is to start with the dollar sign, which indicates that what follows is a variable. In this case, the statement "$my_str = "Hello, World!"" correctly uses the dollar sign before the variable name, allowing PowerShell to recognize it as a variable to hold the string "Hello, World!".

The other options do not conform to the syntax rules for variable assignment in PowerShell. Without the dollar sign at the beginning of the variable name, the PowerShell interpreter cannot identify the variable correctly, leading to errors or unintended behavior. Thus, the necessity of the dollar sign for variable declaration and assignment is what makes this choice correct.

Get further explanation with Examzify DeepDiveBeta

my_str = $ "Hello, World!"

my_str$ = $Hello, World!

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy