Share via

execute powershell command for remote computers at the same time

Boopathi S 3,951 Reputation points
2026-06-16T13:31:29.3433333+00:00

Hello Team,

I am using below powershell command in PowerShell_ISE.

Here the first command executes, and it is not going to second computer till the first command completed.

Invoke-Command -ComputerName "ComputerA" -ScriptBlock { Dism.exe /Online /Add-Package /PackagePath:"C:\Temp\windows11.0-kb5093998-x64_jun26.msu" }

Invoke-Command -ComputerName "ComouterB" -ScriptBlock { Dism.exe /Online /Add-Package /PackagePath:"C:\Temp\windows11.0-kb5093998-x64_jun26.msu" }

Please help me to use a powershell command to execute the powershell command at the same time for Computer A and Computer B without waiting for the first command to complete.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

2 answers

Sort by: Most helpful
  1. Harry Phan 22,230 Reputation points Independent Advisor
    2026-06-16T14:14:42.6266667+00:00

    Right now your commands are running sequentially because Invoke-Command waits for each remote process to finish before moving on. To run them at the same time, you need to start them as background jobs. The simplest way is to use Invoke-Command -AsJob, which will launch the DISM process on each computer in parallel and return immediately. For example:

    Invoke-Command -ComputerName "ComputerA","ComputerB" -ScriptBlock {
        Dism.exe /Online /Add-Package /PackagePath:"C:\Temp\windows11.0-kb5093998-x64_jun26.msu"
    } -AsJob
    

    This way both machines begin processing at once. You can then track progress with Get-Job and collect results using Receive-Job. If you prefer to keep them separate, just run two Invoke-Command calls with -AsJob and monitor each job individually. This is the supported method for parallel execution in PowerShell remoting.

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-06-16T13:31:45.76+00:00

    Use Invoke-Command with multiple computer names in a single call, or run each call as a background job so they execute concurrently.

    1. Single Invoke-Command to both computers at once:
    Invoke-Command -ComputerName 'ComputerA','ComputerB' -ScriptBlock {
        Dism.exe /Online /Add-Package /PackagePath:'C:\Temp\windows11.0-kb5093998-x64_jun26.msu'
    }
    

    This runs the script block on both computers in parallel and returns the combined results.

    1. Or, start each as a background job so the local console does not wait:
    Invoke-Command -ComputerName 'ComputerA' -ScriptBlock {
        Dism.exe /Online /Add-Package /PackagePath:'C:\Temp\windows11.0-kb5093998-x64_jun26.msu'
    } -AsJob
    
    Invoke-Command -ComputerName 'ComputerB' -ScriptBlock {
        Dism.exe /Online /Add-Package /PackagePath:'C:\Temp\windows11.0-kb5093998-x64_jun26.msu'
    } -AsJob
    
    # Optionally monitor jobs
    Get-Job | Receive-Job -Keep
    

    Invoke-Command supports running commands on multiple computers at the same time by specifying all target names in the -ComputerName parameter, or by using -AsJob so each call runs asynchronously.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.