Get-Hotfix from throws error in the middle

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: (:slight_smile: [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.

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. :wink:

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

[pre]

$Servers = Get-Content -Path C:\users\ssubram4\Desktop\Patching\All_2016.txt

foreach ($Server in $Servers)
{
Try
{
Get-HotFix -ComputerName $Server
}
catch
{
#Continue
}
}

[/pre]

or

[pre]

$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
}
}

[/pre]