Boost your confidence for the CompTIA PenTest+ Exam. Train with a quiz featuring flashcards and detailed questions, each offering hints and comprehensive explanations. Prepare thoroughly for your test!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


Which symbol is necessary for variable assignment in PowerShell?

  1. my_str$ = "Hello, World!"

  2. $my_str = "Hello, World!"

  3. my_str = $ "Hello, World!"

  4. my_str$ = $Hello, World!

The correct answer is: $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.