You want to run a script on multiple Linux servers using SSH remoting in PowerShell 7+. Which approach correctly creates sessions and runs the script block on all servers efficiently?
hard📝 Application Q8 of 15
PowerShell - Remote Management
You want to run a script on multiple Linux servers using SSH remoting in PowerShell 7+. Which approach correctly creates sessions and runs the script block on all servers efficiently?
Step 1: Understand session creation for multiple SSH hosts
Creating sessions individually with New-PSSession for each host and collecting them in an array is correct.
Step 2: Use Invoke-Command with session array
Invoke-Command accepts multiple sessions and runs the script block on all efficiently.
Step 3: Eliminate incorrect options
$servers = @('server1','server2'); foreach ($s in $servers) { Invoke-Command -HostName $s -UserName admin -ScriptBlock { uptime } } runs commands sequentially, C uses invalid array for -HostName, D uses -ComputerName which is for WinRM.