0
0
PowerShellscripting~20 mins

VS Code with PowerShell extension - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell Pro in VS Code
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command in VS Code terminal?
You run this command in the VS Code integrated terminal with PowerShell extension enabled:

Get-Process | Where-Object { $_.CPU -gt 100 }

What does this command output?
PowerShell
Get-Process | Where-Object { $_.CPU -gt 100 }
AA list of processes currently using more than 100 seconds of CPU time.
BAn error saying 'CPU' property does not exist.
CAll processes running on the system regardless of CPU usage.
DNo output because the command is incomplete.
Attempts:
2 left
💡 Hint
Think about what the 'Where-Object' filter does with the CPU property.
📝 Syntax
intermediate
1:30remaining
Which PowerShell script snippet correctly defines a function in VS Code with PowerShell extension?
You want to create a function named 'Get-Greeting' that returns 'Hello World'. Which snippet is correct?
Afunction Get-Greeting() => 'Hello World'
Bdef Get-Greeting() { 'Hello World' }
Cfunc Get-Greeting { echo 'Hello World' }
Dfunction Get-Greeting { return 'Hello World' }
Attempts:
2 left
💡 Hint
PowerShell functions use the keyword 'function' without parentheses for parameters if none.
🔧 Debug
advanced
2:00remaining
Why does this PowerShell script fail to run in VS Code with PowerShell extension?
You wrote this script:

Write-Host "Starting script..." $number = 5 if $number -gt 3 { Write-Host "Number is greater than 3" }

When running, you get a syntax error. What is the cause?
PowerShell
Write-Host "Starting script..."
$number = 5
if $number -gt 3
{ Write-Host "Number is greater than 3" }
AMissing parentheses around the condition in the if statement.
BUsing Write-Host instead of Write-Output causes error.
CVariable $number is not initialized properly.
DCurly braces {} are not allowed in PowerShell.
Attempts:
2 left
💡 Hint
PowerShell requires conditions in if statements to be enclosed in parentheses.
🚀 Application
advanced
1:30remaining
How to run a PowerShell script file in VS Code terminal with the PowerShell extension?
You have a script file named 'script.ps1' in your workspace. Which command runs this script correctly in the VS Code integrated terminal?
Arun script.ps1
B.\script.ps1
Cpowershell script.ps1
Dexecute script.ps1
Attempts:
2 left
💡 Hint
In PowerShell, to run a script in the current directory, you prefix with .\
🧠 Conceptual
expert
2:00remaining
What is the purpose of the PowerShell extension in VS Code?
Select the best description of what the PowerShell extension adds to VS Code.
AIt replaces the VS Code terminal with a custom PowerShell-only terminal.
BIt converts PowerShell scripts into executable files automatically.
CIt provides syntax highlighting, IntelliSense, debugging, and integrated terminal support for PowerShell scripts.
DIt allows running PowerShell scripts only on Windows machines.
Attempts:
2 left
💡 Hint
Think about what features help you write and debug scripts inside VS Code.