Bird
0
0

You want to run a script on multiple remote computers Server01 and Server02 using SSH remoting in PowerShell 7+. Which command correctly runs Get-Process on both and collects results?

hard📝 Application Q15 of 15
PowerShell - Remote Management
You want to run a script on multiple remote computers Server01 and Server02 using SSH remoting in PowerShell 7+. Which command correctly runs Get-Process on both and collects results?
AInvoke-Command -Session (New-PSSession -ComputerName Server01), (New-PSSession -ComputerName Server02) -ScriptBlock { Get-Process }
BInvoke-Command -ComputerName Server01,Server02 -UseSSH -ScriptBlock { Get-Process }
CInvoke-Command -HostName Server01,Server02 -ScriptBlock { Get-Process }
DEnter-PSSession -HostName Server01; Enter-PSSession -HostName Server02; Get-Process
Step-by-Step Solution
Solution:
  1. Step 1: Understand running commands on multiple SSH hosts

    Invoke-Command -HostName accepts an array of multiple host names directly in PowerShell 7+.
  2. Step 2: Analyze options

    Invoke-Command -HostName Server01,Server02 -ScriptBlock { Get-Process } runs Get-Process on both remote servers and collects the results.
  3. Step 3: Why other options are incorrect

    A uses New-PSSession -ComputerName, which targets WinRM not SSH. B uses -ComputerName with invalid -UseSSH. C enters sessions sequentially but Get-Process runs locally after.
  4. Final Answer:

    Invoke-Command -HostName Server01,Server02 -ScriptBlock { Get-Process } -> Option C
  5. Quick Check:

    Multiple SSH hosts: -HostName Server01,Server02 [OK]
Quick Trick: Invoke-Command -HostName Server01,Server02 for multiple SSH hosts [OK]
Common Mistakes:
  • Using -ComputerName (WinRM) instead of -HostName for SSH
  • Using invalid -UseSSH parameter
  • Running commands locally after sequential Enter-PSSession

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes