Get-Hotfix from throws error in the middle

Welcome Forums General PowerShell Q&A Get-Hotfix from throws error in the middle

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
3 weeks ago.

  • Author
    Posts
  • #131375

    Participant
    Points: 67
    Rank: Member

    Hi,

    I'm trying to collect all the patches from list of servers which is in notepad. The command i use is Get-Hotfix -computername (Get-Content C:\users\ssubram4\Desktop\Patching\All_2016.txt)

    In the file All_2016.txt, i have 250 servers.If the 10th server is unavailable, iam able to get the hotfix upto 9th server only and i got the below error.

    Get-Hotfix : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At line:1 char:1
    + Get-Hotfix -computername (Get-Content C:\users\ssubram4\Desktop\Patch ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Get-HotFix], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetHotFixCom
    mand

    I would like to skip the unreachable servers and move on to next server to the hotfix.
    Kindly help me with the SAME SYNTAX.

  • #131378

    Participant
    Points: 398
    Helping Hand
    Rank: Contributor

    So you need to check the availability of each single server before you query the hotfixes. You can do this in a loop with Test-Connection.

    Test-Connection -ComputerName "ComputerName" -Count 1 Quiet

    ... returns a $true if the target computer is available and a $false if not. 😉

  • #131439

    Participant
    Points: 211
    Helping Hand
    Rank: Participant

    You need to use try/catch block or ping the server before executing the command...

    
    $Servers = Get-Content -Path C:\users\ssubram4\Desktop\Patching\All_2016.txt
    
    foreach ($Server in $Servers)
    {
    Try
    {
    Get-HotFix -ComputerName $Server
    }
    catch
    {
    #Continue
    }
    }
    
    

    or

    
    $Servers = Get-Content -Path C:\users\ssubram4\Desktop\Patching\All_2016.txt
    
    foreach ($Server in $Servers)
    {
    if (Test-Connection -ComputerName $Server -Count 1 -Quiet)
    {
    Get-HotFix -ComputerName $Server
    }
    }
    
    

You must be logged in to reply to this topic.