ps1 is on remote machine . I am running below command from some other mahcine.
Is there any difference between using both below script ---
invoke-command -computer $MachineName -command { C:\hello.ps1 }
invoke-command -computer $MachineName -scriptblock{ C:\hello.ps1 }
Also, I am going to use for loop for multiple machine having same script name but having diff sequence of work that is located on each remote machine only . Want to understand the execution for second machine will go only if first get completed . Correct ?
There is no difference in execution. -command
is merely an alias for scriptblock
. You can verify this by getting the parameter info for the invoke-command
command
(Get-Command -Name Invoke-Command).Parameters.Values | select name, aliases
Yes, the execution is sequential. The command you specify will execute on the second machine after the command has completed on the first machine.
These commands run synchronously (one at a time). When the commands complete, the output of the commands from all of the computers is saved in the $version variable. The output includes the name of the computer from which the data originated.