Link to home
Start Free TrialLog in
Avatar of davesnb
davesnbFlag for Canada

asked on

powershell and invoke-command

Hi Ee,

i have a script that invokes a script residing on remote host with ;


invoke-command -computername computer1  - command { c:\script\somescript.ps1}


invoke-command -computername computer2 - command { c:\script\somescript.ps1}

Pardon my syntax , it works gret however , is it waiting for the first script to completely finish/exit before it moves onto the second invoke-command , or are they running concurrently ?

if not running concurrently , is there a parameter to specify this ?
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's not accurate.  You can achieve "fan out remoting" with PowerShell while using the Invoke-Command cmdlet by simply specifying more than one computer for the -ComputerName parameter, for example:

Invoke-Command -ComputerName server1,server2,server3 -ScriptBlock {Get-Service}

Open in new window

or

Invoke-Command -ComputerName (Get-Content .\servers.txt) -ScriptBlock {Get-Service}

Open in new window

https://blogs.technet.microsoft.com/heyscriptingguy/2012/07/25/an-introduction-to-powershell-remoting-part-three-interactive-and-fan-out-remoting/

If you wanted one command to run at a time, you could just use a ForEach-Object loop:

Get-Content .\servers.txt | ForEach-Object {
    Invoke-Command -ComputerName $_ -ScriptBlock {Get-Service}
}

Open in new window

Jason - How is it not accurate?  You go on to describe the exact same thing as I did in my last paragraph.
Avatar of davesnb

ASKER

Thanks Guys