Bird
0
0

You want to run a script file named cleanup.ps1 on multiple remote computers listed in servers.txt. Which command correctly uses Invoke-Command to do this?

hard📝 Application Q8 of 15
PowerShell - Remote Management
You want to run a script file named cleanup.ps1 on multiple remote computers listed in servers.txt. Which command correctly uses Invoke-Command to do this?
AInvoke-Command -ComputerName servers.txt -ScriptBlock { .\cleanup.ps1 }
BInvoke-Command -ComputerName (Get-Content servers.txt) -FilePath cleanup.ps1
CInvoke-Command -ScriptBlock cleanup.ps1 -ComputerName (Get-Content servers.txt)
DInvoke-Command -FilePath servers.txt -ComputerName cleanup.ps1
Step-by-Step Solution
Solution:
  1. Step 1: Read computer names from file

    (Get-Content servers.txt) reads the list of computers.
  2. Step 2: Use -FilePath to run script on those computers

    -FilePath cleanup.ps1 runs the script file remotely.
  3. Final Answer:

    Invoke-Command -ComputerName (Get-Content servers.txt) -FilePath cleanup.ps1 -> Option B
  4. Quick Check:

    Use -FilePath with computer list from Get-Content [OK]
Quick Trick: Use Get-Content to read computers, -FilePath to run scripts [OK]
Common Mistakes:
  • Passing filename as computer name
  • Using -ScriptBlock with script filename directly
  • Swapping parameters incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes