Challenge - 5 Problems
Invoke-Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this Invoke-Command script?
Consider this PowerShell script that runs a command on a remote computer named 'Server01'. What will be the output?
PowerShell
Invoke-Command -ComputerName Server01 -ScriptBlock { Get-Date -Format 'yyyy-MM-dd' }Attempts:
2 left
💡 Hint
Invoke-Command runs the script block on the remote computer specified by -ComputerName.
✗ Incorrect
Invoke-Command runs the script block on the remote computer 'Server01', so the output is the date on that remote machine, not the local one.
📝 Syntax
intermediate2:00remaining
Which option correctly uses Invoke-Command to run a script block on multiple computers?
You want to run the command 'hostname' on two remote computers: 'PC1' and 'PC2'. Which syntax is correct?
Attempts:
2 left
💡 Hint
The -ComputerName parameter accepts a comma-separated list of computer names.
✗ Incorrect
The correct way is to pass multiple computer names as an array or comma-separated list. Option C is correct syntax.
🔧 Debug
advanced2:00remaining
Why does this Invoke-Command script fail with an error?
This script tries to run a command on a remote computer but fails. What is the cause?
PowerShell
Invoke-Command -ComputerName Server01 -ScriptBlock { Get-Process } -Credential $nullAttempts:
2 left
💡 Hint
Check the use of the -Credential parameter and what values it accepts.
✗ Incorrect
Passing $null to -Credential is invalid because it expects a PSCredential object or nothing. This causes the command to fail.
🚀 Application
advanced2:00remaining
How to capture output from multiple remote computers using Invoke-Command?
You want to run 'Get-Service' on 'ServerA' and 'ServerB' and save the combined output locally. Which script achieves this?
Attempts:
2 left
💡 Hint
Invoke-Command returns output objects that can be stored in a variable.
✗ Incorrect
Option A runs the command on both servers and stores all output in $results as a combined collection.
🧠 Conceptual
expert2:00remaining
What happens if you use Invoke-Command with -AsJob parameter?
You run this command: Invoke-Command -ComputerName Server01 -ScriptBlock { Start-Sleep -Seconds 10; 'Done' } -AsJob. What is the behavior?
Attempts:
2 left
💡 Hint
The -AsJob parameter runs the command in the background.
✗ Incorrect
Using -AsJob runs the command asynchronously as a background job. Output is not immediate and must be retrieved with Receive-Job.