Question

Difficulty: MediumBasic Scripting Languages and Constructs

A tier 2 support technician is auditing administrative scripts created for system maintenance across multi-platform client devices. The technician must identify syntax elements and construct formats specific to Microsoft PowerShell (`.ps1`). Which of the following statements correctly describe PowerShell scripting syntax and variable usage? (Select TWO)

  1. Variables in PowerShell are designated with a dollar sign prefix (e.g., serviceState),andsystemenvironmentvariablesareaccessedusingtheserviceState), and system environment variables are accessed using the env: namespace.Answer
  2. Comparison operations in PowerShell conditional statements utilize hyphenated operators such as -eq (equal) and -gt (greater than) instead of standard mathematical symbols.Answer
  3. C
    Environment variables must be wrapped inside percent signs (e.g., %serviceState%), and conditional constructs require a THEN keyword before script execution blocks.
  4. D
    Variable assignment requires explicit declaration using the SET keyword, and string values must be enclosed in square brackets instead of quotes.

Answer

PowerShell variables are prefixed with a dollar sign with environment variables using the $env: prefix, and PowerShell comparison operations use hyphenated operators such as -eq and -gt rather than traditional comparison symbols.
PowerShell scripts (.ps1) use a dollar sign ()todeclareuservariablesandthe) to declare user variables and the env: drive provider prefix to access environment variables. In addition, PowerShell utilizes hyphenated comparison operators (such as -eq, -ne, -gt, and -lt) within conditional statements to avoid syntax conflicts with shell redirection operators.

Step-by-Step Solution

1
Analyze PowerShell variable syntax requirements.
Confirm that PowerShell designates variables using the 'prefixandaccessesenvironmentvariablesvia' prefix and accesses environment variables via ' env:'.
PowerShell relies on an object-oriented scripting model where 'denotesvariableidentifiersand' denotes variable identifiers and ' env:' accesses environment providers.
2
Evaluate comparison operators used in PowerShell conditional constructs.
Identify that PowerShell uses operators like '-eq', '-ne', '-lt', and '-gt' inside conditional blocks.
Because symbols like '>' and '<' are reserved for output redirection in command shells, PowerShell uses hyphenated text operators for comparison.
3
Differentiate PowerShell constructs from legacy Windows Batch (.bat) scripting syntax.
Rule out legacy Batch constructs such as '%VAR%' variable wrapping and 'SET' assignment commands.
Batch scripting syntax does not apply to PowerShell runtime environments.

Key Concept

PowerShell Scripting Syntax and Constructs
Rate this question