Question

Difficulty: MediumBasic Scripting Languages and Constructs

A desktop support technician is writing a Windows PowerShell script (.ps1) to automate user workstation deployment. The script needs to check the value of the system environment variable named LOGONSERVER to verify which domain controller authenticated the current user session. Which of the following syntax constructs should the technician use to access this environment variable inside the PowerShell script?

  1. $env:LOGONSERVERAnswer
  2. B
    %LOGONSERVER%
  3. C
    $LOGONSERVER
  4. D
    echo %LOGONSERVER%

Answer

$env:LOGONSERVER
In Microsoft PowerShell (.ps1), environment variables are exposed via the environment drive provider and referenced using the env:prefixattachedtothevariablename,suchasenv: prefix attached to the variable name, such as env:LOGONSERVER.

Step-by-Step Solution

1
Identify the scripting language and runtime environment.
The script uses the .ps1 file extension, indicating Windows PowerShell.
Scripting languages differ in how environment variables and local variables are denoted.
2
Recall the variable referencing syntax specific to PowerShell environment variables.
PowerShell exposes OS environment variables through the $env: drive provider.
Using $env:VARIABLE_NAME allows PowerShell scripts to directly read or write environment variables.

Key Concept

PowerShell Environment Variable Syntax
Rate this question