A system administrator is writing a Windows PowerShell script (`.ps1`) to automate user environment auditing. The script needs to retrieve the built-in system environment variable for the logged-in username and display it to the console. Which of the following code snippets uses the correct syntax to reference an environment variable in PowerShell?
- Write-Output $env:USERNAMECevap
- BWrite-Output %USERNAME%
- CWrite-Output $USER
- DWrite-Output %env:USERNAME%
Cevap
The command line using 'Write-Output $env:USERNAME' correctly references an environment variable in PowerShell.
In Windows PowerShell, system environment variables are accessed via the environment drive provider using the ' env:USERNAME).
Adım Adım Çözüm
Anahtar Kavram
PowerShell Environment Variable Syntax