0
0
PowerShellscripting~10 mins

Invoke-Command in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run a command on a remote computer named 'Server01'.

PowerShell
Invoke-Command -ComputerName [1] -ScriptBlock { Get-Process }
Drag options to blanks, or click blank then click option'
AServer01
BLocalHost
CRemotePC
DMyComputer
Attempts:
3 left
💡 Hint
Common Mistakes
Using the local computer name instead of the remote computer name.
Leaving the -ComputerName parameter empty.
2fill in blank
medium

Complete the code to run the command 'Get-Service' on the remote computer 'Server02'.

PowerShell
Invoke-Command -ComputerName Server02 -ScriptBlock { [1] }
Drag options to blanks, or click blank then click option'
AGet-Process
BStart-Service
CStop-Service
DGet-Service
Attempts:
3 left
💡 Hint
Common Mistakes
Using a command unrelated to services.
Forgetting to put the command inside the script block.
3fill in blank
hard

Fix the error in the code to correctly run 'Get-EventLog' on 'Server03'.

PowerShell
Invoke-Command -ComputerName Server03 -ScriptBlock [1]
Drag options to blanks, or click blank then click option'
A{ Get-EventLog -LogName System }
BGet-EventLog -LogName System
C[Get-EventLog -LogName System]
D(Get-EventLog -LogName System)
Attempts:
3 left
💡 Hint
Common Mistakes
Not using curly braces for the script block.
Using parentheses or square brackets instead of curly braces.
4fill in blank
hard

Fill both blanks to run 'Get-Process' on 'Server04' and store the result in a variable.

PowerShell
$processes = Invoke-Command -ComputerName [1] -ScriptBlock [2]
Drag options to blanks, or click blank then click option'
AServer04
B{ Get-Process }
CServer05
D{ Get-Service }
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up computer names.
Not using curly braces for the script block.
5fill in blank
hard

Fill all three blanks to run 'Get-Service' on 'Server06' and filter services with status 'Running'.

PowerShell
$runningServices = Invoke-Command -ComputerName [1] -ScriptBlock { Get-Service | Where-Object { $_.Status -eq '[2]' } } | Where-Object { $_.Name -like '[3]' }
Drag options to blanks, or click blank then click option'
AServer06
BRunning
C*
DStopped
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong computer name.
Using wrong status like 'Stopped' instead of 'Running'.
Not using wildcard '*' for name filter.