Powershell Command line to ignore WARNING: Attempting to reconnect to Computer-A

Boopathi S 4,011 Reputation points
2026-06-17T17:26:56.1+00:00

Hello,

I am using the below command to connect devices remotely. If Computer-A is disconnected from network then it is keep trying to connect again.

is there any command line to add so that it will move to next computer if it is not reachable in network

Invoke-Command -ComputerName 'Computer-A', 'Computer-B' -ScriptBlock { Dism.exe /Online /Add-Package /PackagePath:"C:\Temp\windows11.0-kb5093998-x64.msu" }

WARNING: The network connection to Computer-A has been interrupted. Attempting to reconnect for up to 4 minutes...

WARNING: Attempting to reconnect to Computer-A ...

WARNING: Attempting to reconnect to Computer-A ...

WARNING: Attempting to reconnect to Computer-A ...

WARNING: Attempting to reconnect to Computer-A ...

WARNING: The reconnection attempt to Computer-A failed. Attempting to disconnect the session...

WARNING: Computer Computer-A has been successfully disconnected.

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

2 answers

Sort by: Most helpful
  1. HLBui 9,890 Reputation points Independent Advisor
    2026-06-17T18:22:25.42+00:00

    Hi Boopathi S

    By default, Invoke-Command will keep retrying a disconnected machine for a few minutes, which is why you’re seeing those warnings. There isn’t a built-in “skip immediately” flag, but you can work around it by checking reachability before you try the command. A common trick is to wrap it with a Test-Connection or Test-NetConnection check, so you only send the command to machines that respond. For example, you could loop through your list of computers, ping each one, and if it’s alive, then run Invoke-Command on it. That way, if Computer-A is offline, it just moves on to Computer-B without wasting time. Another option is to use -ErrorAction SilentlyContinue with some custom logic, but honestly the pre-check with Test-Connection is cleaner and gives you more control. Think of it like building your own “skip list” logic instead of relying on PowerShell’s default retry behavior.

    If everything is okay, don't forget to share your experience with the issue by "Accept answer". If you need more information, feel free to leave a message. We are happy to help!

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. AI answer

    2026-06-17T17:27:09.0533333+00:00

    Use Invoke-Command with shorter timeouts and error handling so it does not sit waiting on an unreachable computer.

    Invoke-Command itself does not expose a direct "skip unreachable computer immediately" switch, but it can be combined with session options and per-computer calls to reduce wait time and move on faster.

    Example approach:

    1. Create a PSSessionOption with low connection and operation timeouts.
    2. Loop each computer individually so a failure on one does not delay the others.
    $sessionOptions = New-PSSessionOption -OperationTimeout 60000  # 60 seconds
    
    $computers = 'Computer-A','Computer-B'
    
    foreach ($c in $computers) {
        try {
            Invoke-Command -ComputerName $c `
                           -ScriptBlock { Dism.exe /Online /Add-Package /PackagePath:"C:\Temp\windows11.0-kb5093998-x64.msu" } `
                           -SessionOption $sessionOptions `
                           -ErrorAction Stop
        }
        catch {
            # Log and move on to next computer
            Write-Warning "Skipping $c: $_"
        }
    }
    

    This configuration:

    • Limits how long Invoke-Command waits for operations on each computer.
    • Uses try/catch with -ErrorAction Stop so that when a connection fails, the script immediately moves to the next computer.

    If needed, additional New-PSSessionOption parameters (for example, shorter -OpenTimeout) can further reduce how long it waits on unreachable machines.


    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.