How can I skip the error and run the script?

1

Run the command and getting the below Error Mgs, can you help how could I skip the error and more further and create the separate file with failed servers

@Get@()

Get-HotFix -ComputerName $Ser -Id kbXXXXX -ErrorAction SilentlyContinue -ErrorVariable err |  select HotfixID, Description, InstalledOn, CSName| Sort-Object InstalledOn | 
ConvertTo-Csv -NoTypeInformation  |  Out-File "xxx.csv"

*Error Mgs*

Get-HotFix : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:1 char:1
+ Get-HotFix -ComputerName $Ser -Id kbXXXXXX -ErrorAction SilentlyContinue -Error ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-HotFix], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetHotFixCommand
powershell
asked on Server Fault May 16, 2017 by Rohan • edited May 17, 2017 by Uwe Keim

1 Answer

0

We don't know what is stored in your variable $ser but I literally just had this same problem. I know this was answered in comments suggestion to use a for loop. Tossing in another answer.

In my case I was importing a csv list and looping through. For my computername variable I forgot to append the CSV column name so powershell gets just the value of the servername. Powershell was trying to resolve the entire object as the servername.

So for example:

Get-HotFix -ComputerName $Ser.Name
answered on Server Fault May 18, 2017 by Ben Force

User contributions licensed under CC BY-SA 3.0