I have declined around 390,000 driver updates and now sitting on Declined updates. How do I delete these? I tried powershell script below where it works if you have less than 1,000 to decline but now keeps failing with errors due to the huge number of declined updates. Any ideas? Thanks.<\/p>\n
\n\n
Advertisement$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
\n$declined=$wsus.GetUpdates() | Where {$.IsDeclined -eq $true}
\n$declined| ForEach-Object {$wsus.DeleteUpdate($<\/em>.Id.UpdateId.ToString()); Write-Host $_.Title removed }<\/p>\n<\/blockquote>\n<\/blockquote>","upvoteCount":5,"answerCount":11,"datePublished":"2023-06-16T02:45:21.000Z","author":{"@type":"Person","name":"dionoliva","url":"https://community.spiceworks.com/u/dionoliva"},"suggestedAnswer":[{"@type":"Answer","text":"
AdvertisementI have declined around 390,000 driver updates and now sitting on Declined updates. How do I delete these? I tried powershell script below where it works if you have less than 1,000 to decline but now keeps failing with errors due to the huge number of declined updates. Any ideas? Thanks.<\/p>\n
\n\n$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
\n$declined=$wsus.GetUpdates() | Where {$.IsDeclined -eq $true}
\n$declined| ForEach-Object {$wsus.DeleteUpdate($<\/em>.Id.UpdateId.ToString()); Write-Host $_.Title removed }<\/p>\n<\/blockquote>\n<\/blockquote>","upvoteCount":5,"datePublished":"2023-06-16T02:45:21.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/1","author":{"@type":"Person","name":"dionoliva","url":"https://community.spiceworks.com/u/dionoliva"}},{"@type":"Answer","text":"Have you tried using the server cleanup wizard via the GUI (ensuring the “Unneeded update files” checkbox is checked)?<\/p>","upvoteCount":1,"datePublished":"2023-06-16T10:20:04.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/2","author":{"@type":"Person","name":"chris-kelly","url":"https://community.spiceworks.com/u/chris-kelly"}},{"@type":"Answer","text":"
Barring someone having a better idea, you could try piping the get with | Select-Object -First 1000<\/p>\n
Or something similar. I’m not the Powershell wizard by any means.<\/p>","upvoteCount":0,"datePublished":"2023-06-16T19:35:14.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/3","author":{"@type":"Person","name":"kevinhughes2","url":"https://community.spiceworks.com/u/kevinhughes2"}},{"@type":"Answer","text":"
Server clean up wizard doesnt clear up the declined updates unfortunately.<\/p>\n
Anyone know how to apply the syntax for selecting just the first 1000 of the declined updates to be deleted in powershell?<\/p>","upvoteCount":0,"datePublished":"2023-06-22T23:58:07.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/4","author":{"@type":"Person","name":"dionoliva","url":"https://community.spiceworks.com/u/dionoliva"}},{"@type":"Answer","text":"
[reflection.assembly]::LoadWithPartialName(\"Microsoft.UpdateServices.Administration\")\n$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();\n$declined=$wsus.GetUpdates() | Where {$_.IsDeclined -eq $true} | Select-Object -First 50 \n$declined.Count\n<\/code><\/pre>\n
Like I said above, just pipe your get through Select-object with First and a number. The above returns 50 as a count.<\/p>\n
Running it without the pipe<\/p>\n
[reflection.assembly]::LoadWithPartialName(\"Microsoft.UpdateServices.Administration\")\n$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();\n$declined=$wsus.GetUpdates() | Where {$_.IsDeclined -eq $true} \n$declined.Count\n<\/code><\/pre>\n
Returns 426 in my case, which is the current number of declined updates in my DB … I’m overdue for a purge.<\/p>\n
I did not include the delete syntax because I didn’t want to remove anything from my live server, but the foreach looks all right at first glance<\/p>","upvoteCount":0,"datePublished":"2023-06-24T12:33:37.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/5","author":{"@type":"Person","name":"kevinhughes2","url":"https://community.spiceworks.com/u/kevinhughes2"}},{"@type":"Answer","text":"
[reflection.assembly]::LoadWithPartialName(\"Microsoft.UpdateServices.Administration\")\n$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();\n$loopcontrol=$wsus.GetUpdates() | Where {$_.IsDeclined -eq $true}\n$control=$loopcontrol.Count\nDO{\nWrite-Host \"$control left to go\"\n$declined=$wsus.GetUpdates() | Where {$_.IsDeclined -eq $true}| Select-Object -First 1000 \n$declined| ForEach-Object {$wsus.DeleteUpdate($_.Id.UpdateId.ToString()); Write-Host $_.Title removed}\n$control=$control-1000\n} Until ($control -lt 0)\n\n<\/code><\/pre>\n
This should do the trick … it might bomb/bitch on the last loop though<\/p>","upvoteCount":1,"datePublished":"2023-06-24T13:55:42.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/6","author":{"@type":"Person","name":"kevinhughes2","url":"https://community.spiceworks.com/u/kevinhughes2"}},{"@type":"Answer","text":"
Once my post gets out of moderation (my bad used the female dog word to describe potential behavior on last loop iteration), just one note:<\/p>\n
Run it in ISE just in case it doesn’t stop when it should. I’m no Powershell guru.<\/p>","upvoteCount":0,"datePublished":"2023-06-24T14:04:56.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/7","author":{"@type":"Person","name":"kevinhughes2","url":"https://community.spiceworks.com/u/kevinhughes2"}},{"@type":"Answer","text":"
Thank you Kevin for having a go in helping me with this issue. Unfortunately, I get the errors below when I run it. Im not an expert in Powershell myself and not sure what these errors means:<\/p>\n
GAC Version Location<\/p>\n
\n<\/a>True v4.0.30319 C:\\Windows\\Microsoft.Net\\assembly\\GAC_MSIL\\Microsoft.UpdateServices.Administration\\v4.0_4.0.0…
\nException calling “GetUpdates” with “0” argument(s): \"Client found response content type of ‘text/html; charset=utf-8’, but expected ‘text/xml’.
\nThe request failed with the error message:<\/h2>\n\n\n\nOverflow or underflow in the arithmetic operation.\n\n\nbody {font-family:\"Verdana\";font-weight:normal;font-size: .7em;color:black;}\np {font-family:\"Verdana\";font-weight:normal;color:black;margin-top: -5px}\nb {font-family:\"Verdana\";font-weight:bold;color:black;margin-top: -5px}\nH1 { font-family:\"Verdana\";font-weight:normal;font-size:18pt;color:red }\nH2 { font-family:\"Verdana\";font-weight:normal;font-size:14pt;color:maroon }\npre {font-family:\"Consolas\",\"Lucida Console\",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}\n.marker {font-weight: bold; color: black;text-decoration: none;}\n.version {color: gray;}\n.error {margin-bottom: 10px;}\n.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }\n@media screen and (max-width: 639px) {\npre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }\n}\n@media screen and (max-width: 479px) {\npre { width: 280px; }\n}\n\n\n\nServer Error in '/ApiRemoting30' Application.
<\/h1>\nOverflow or underflow in the arithmetic operation.<\/i> <\/h2><\/span>\n\n Description: <\/b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.\n
\n Exception Details: <\/b>System.ArithmeticException: Overflow or underflow in the arithmetic operation.
\nSource Error:<\/b>
\n\n
\n \n \nAn unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.<\/code>\n<\/td>\n<\/tr>\n<\/tbody><\/table>\n
\nStack Trace:<\/b>
\n\n
\n \n
[ArithmeticException: Overflow or underflow in the arithmetic operation.]\n[HttpException (0x80004005): An error occurred while communicating with the remote host. The error code is 0x80070216.]\nSystem.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect) +4478701\nSystem.Web.Hosting.IIS7WorkerRequest.FlushCore(Boolean keepConnected, Int32 numBodyFragments, IntPtr[] bodyFragments, Int32[] bodyFragmentLengths, Int32[] bodyFragmentTypes) +11947077\nSystem.Web.Hosting.IIS7WorkerRequest.FlushCachedResponse(Boolean isFinal) +743\nSystem.Web.HttpResponse.UpdateNativeResponse(Boolean sendHeaders) +1330\nSystem.Web.HttpRuntime.FinishRequestNotification(IIS7WorkerRequest wr, HttpContext context, RequestNotificationStatus& status) +182\n<\/pre><\/code>\n<\/td>\n<\/tr>\n<\/tbody><\/table>\n
\n
\nVersion Information:<\/b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3930.0\n\n\n\n\n--.\"\nAt line:3 char:1\n+ $declined=$wsus.GetUpdates() | Select-Object -First 10 | Where {$_.Is ...\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException\n+ FullyQualifiedErrorId : InvalidOperationException\nYou cannot call a method on a null-valued expression.
\nAt line:4 char:28<\/p>\n\n
- … ForEach-Object {$wsus.DeleteUpdate($_.Id.UpdateId.ToString()); Write- …<\/li>\n
- \n
<\/code><\/pre>\n<\/li>\n
- CategoryInfo : InvalidOperation: (
<\/span>, RuntimeException<\/li>\n
- FullyQualifiedErrorId : InvokeMethodOnNull<\/li>\n<\/ul>","upvoteCount":0,"datePublished":"2023-06-30T00:07:24.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/8","author":{"@type":"Person","name":"dionoliva","url":"https://community.spiceworks.com/u/dionoliva"}},{"@type":"Answer","text":"
I get you want to write it yourself for the accomplishment … I think that whole mess of errors comes down to you rearranging the order of the pipes, given it shows your line 3 running select-object first 10 before checking if the update is declined. Powershell pipes process left to right and the order is important. Running get-updates returns all the updates (declined or not, since you didn’t tell it otherwise) then you selected the first 10, then you checked those 10 for being declined. If none of the first 10 are declined, the command as a whole will return a null set. Then your next line tries to run for each on nothing - which is going to throw an error Now look at my code: Get updates where declined is true returns the giant set of declined updates, I then pipe that set of objects into select object first 1000 That will return the first 1000 objects that are declined, which gives the following for each something to work with.<\/p>","upvoteCount":0,"datePublished":"2023-06-30T09:36:14.000Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/9","author":{"@type":"Person","name":"kevinhughes2","url":"https://community.spiceworks.com/u/kevinhughes2"}},{"@type":"Answer","text":"
Thanks Kevin, worked perfectly for me.<\/p>","upvoteCount":0,"datePublished":"2024-04-18T17:11:44.850Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/10","author":{"@type":"Person","name":"karimboroumand","url":"https://community.spiceworks.com/u/karimboroumand"}},{"@type":"Answer","text":"
Just come across this and worked like a dream!!<\/p>\n
Thanks<\/p>","upvoteCount":0,"datePublished":"2025-05-02T12:00:03.255Z","url":"https://community.spiceworks.com/t/deleting-declined-updates-in-wsus/953882/11","author":{"@type":"Person","name":"spiceuser-lgr6","url":"https://community.spiceworks.com/u/spiceuser-lgr6"}}]}}