restart-computer asjob error results in no location job RRS feed

  • Question

  • This command works great for restarting 1 or more computers in an array.

    restart-computer -ComputerName $restartlist -Force -AsJob -ErrorAction SilentlyContinue

    Until it cannot resolve the DNS name of that computer as shown in this error.

    restart-computer : Computer name CLIENT1 cannot be resolved with the exception: One or more errors occurred..
    At C:\Program Files\GSSMiniConsoleBeta\MiniConsole.ps1:2111 char:10
    +   $job = restart-computer -ComputerName $restartlist -Force -AsJob -E ...
    +          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (CLIENT1:String) [Restart-Computer], InvalidOperationException
        + FullyQualifiedErrorId : AddressResolutionException,Microsoft.PowerShell.Commands.RestartComputerCommand

    While I can handle the error code, it still creates a job that has no location.  It then runs forever.  If you try to stop the job, it locks up powershell.  

    Another odd quark is that if you use stop-computer with the same parameters, it detects an error properly and never makes the job.  

    Lastly, if the array has multiple computers and even one restarts or at least resolves it's DNS name, the job works OK and just excludes the one location that failed.  

    Does anyone have a fancy trick to avoid creating a no location job that can execute in under a second?

    Tuesday, November 7, 2017 12:59 AM

All replies

  • Yup.  That is how it works.

    You need to check the exisitence of all computers first.

    $restartlist =  $restartlist |where{Test-Connection $_ -Count 1 -Quiet }

    A workflow would  not have this problem.


    Tuesday, November 7, 2017 1:18 AM