Invoke-Command lets you run commands on one or many computers from your own computer. It helps you control other machines easily without logging into each one.
You want to check the disk space on several computers at once.
You need to restart a service on remote servers quickly.
You want to gather system information from multiple machines.
You need to run a script on a remote computer without opening a remote session.
You want to automate tasks across many computers in your network.
But get an error: "Access is denied." What is the most likely cause?
medium
A. The script block syntax is incorrect
B. Get-Service cmdlet does not exist
C. Server01 is offline
D. You do not have permission to run commands on Server01
Solution
Step 1: Analyze the error message
"Access is denied" indicates a permissions issue, not syntax or cmdlet existence.
Step 2: Match error to cause
Permission problems usually mean the user lacks rights to run remote commands on Server01.
Final Answer:
You do not have permission to run commands on Server01 -> Option D
Quick Check:
Access denied = permission issue [OK]
Hint: Access denied usually means permission problem [OK]
Common Mistakes:
Assuming syntax error causes access denied
Thinking server offline causes access denied
Believing cmdlet absence causes access denied
5. You want to run a command on multiple remote computers: Server01, Server02, and Server03. Which command correctly runs Get-EventLog -LogName System -Newest 5 on all three at once?
hard
A. Invoke-Command -ComputerName @('Server01', 'Server02', 'Server03') -ScriptBlock { Get-EventLog -LogName System -Newest 5 }
B. Invoke-Command -ComputerName 'Server01 Server02 Server03' -ScriptBlock { Get-EventLog -LogName System -Newest 5 }
C. Invoke-Command -ComputerName Server01 Server02 Server03 -ScriptBlock { Get-EventLog -LogName System -Newest 5 }
D. Invoke-Command -ComputerName Server01; Server02; Server03 -ScriptBlock { Get-EventLog -LogName System -Newest 5 }
Solution
Step 1: Understand how to specify multiple computers
The -ComputerName parameter accepts an array of strings to target multiple computers.
Step 2: Evaluate options for correct array syntax
Invoke-Command -ComputerName @('Server01', 'Server02', 'Server03') -ScriptBlock { Get-EventLog -LogName System -Newest 5 } uses an array @('Server01', 'Server02', 'Server03'), which is the correct way to pass multiple names. Invoke-Command -ComputerName Server01 Server02 Server03 -ScriptBlock { Get-EventLog -LogName System -Newest 5 } uses space-separated names without commas or array syntax, which is invalid. Invoke-Command -ComputerName 'Server01 Server02 Server03' -ScriptBlock { Get-EventLog -LogName System -Newest 5 } passes a single string with spaces, treated as one name. Invoke-Command -ComputerName Server01; Server02; Server03 -ScriptBlock { Get-EventLog -LogName System -Newest 5 } uses semicolons, which is invalid syntax.
Final Answer:
Invoke-Command -ComputerName @('Server01', 'Server02', 'Server03') -ScriptBlock { Get-EventLog -LogName System -Newest 5 } -> Option A
Quick Check:
Use array syntax @() for multiple computers [OK]
Hint: Use @() array for multiple computer names [OK]
Common Mistakes:
Using space-separated names without commas or array syntax
Passing all names as one string
Using semicolons to separate names
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.