Optimize-WsusServer icon indicating copy to clipboard operation
Optimize-WsusServer copied to clipboard

Issue with deepclean & suggestions

Open karsayor opened this issue 3 years ago • 8 comments

Hi,

First of all, waht a great work. Thank you very much because it's really the tools that missed to manage WSUS...

I have two issues and one suggestion at the end

  1. It seems that even if you fixed DeepClean, it still doesn't remove updates that are declined.
  2. I added Windows Server 2012 to the $unneededUpdatesbyProductTitles list but it seems to also decline updates for 2012 R2
  3. It would be nice I think to add a feature to the optimize daily task to delete declined updates olders than X days, just to make sure the DB is not growing forever for old updates...

I think it's nice to decline old updates, but then they should be once removed from DB, hence suggestion 3 as well as bugfix 1 don't you think ?

karsayor avatar Aug 17 '21 21:08 karsayor

I'm also experiencing issues with Deep Clean not working like it should!

DANG3Rv avatar Sep 02 '21 13:09 DANG3Rv

@karsayor

  1. The DeepClean function declines updates using IUpdate.Decline() method. Microsoft does have a method that can do this, but currently deleting updates is handled by the built-in WSUS cleanup.
  2. This does a simple string match, so you'll have to try to use a more specific string. This could be redesigned, but probably won't be at this time.
  3. Related to 1 built-in commands should do this, but it won't happen immediately and I can't find good documentation on what the criteria are for deleting updates.

Deleting updates is possible and not difficult, I will look into that.

awarre avatar Nov 02 '21 16:11 awarre

Microsoft recommends NOT to delete declined updates

If you choose to ignore Microsoft's recommendation:

This is untested so use at your own risk, but I believe beneath any $update.Decline() you could add:

$wsusServer.DeleteUpdate($update.Update.Id.UpdateId)

I wouldn't test that in a production environment, and this is not how I would implement this feature, but it should delete the updates being declined. It will not delete already declined updates or wait for any sort of delay before attempting to delete them.

The discussion I linked references a simple method to delete all declined updates if you so choose.

awarre avatar Nov 02 '21 16:11 awarre

Deleting updates works I did with an other script, it's just that sometimes WSUS does resync all updates and issue is back again.. unfortunately, because we do not need such a huge WSUS with years and years old updates and drivers.

karsayor avatar Nov 04 '21 14:11 karsayor

Something which has been working really well in our environment, is having a script separate from this one which can be scheduled in task scheduler to automatically decline superseded updates, and then having the -DeepClean and -Optimize-server scheduled tasks set to run AFTER the initial script to decline superseded updates.

This has brought our storage requirement down from 150GB+ to around 90GB, and i have it set to run weekly.

`#Change server name and port number and $True if it is on SSL

$Computer = $env:ServerHostName $Domain = $env:DOMAIN $FQDN = "$Computer" + "." + "$Domain" + ".local" [String]$updateServer1 = $FQDN [Boolean]$useSecureConnection = $False [Int32]$portNumber = 8530

Load .NET assembly

[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")

$count = 0

Connect to WSUS Server

$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer("Server.domain.local",$useSecureConnection,$portNumber)

write-host "<<<Connected sucessfully >>>" -foregroundcolor "yellow"

$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope

$u=$updateServer.GetUpdates($updatescope )

foreach ($u1 in $u )

{

if ($u1.IsSuperseded -eq 'True')

{

write-host Decline Update : $u1.Title

$u1.Decline()

$count=$count + 1

}

}

write-host Total Declined Updates: $count

trap

{

write-host "Error Occurred"

write-host "Exception Message: "

write-host $_.Exception.Message

write-host $_.Exception.StackTrace

exit

}

EOF`

This is the script i use to decline superseded updates.

DANG3Rv avatar Nov 05 '21 10:11 DANG3Rv

@DANG3Rv Thanks for your script. You should edit your comment and remove your domain.

ElmoFuntz avatar Dec 02 '21 20:12 ElmoFuntz

@ElmoFuntz Thanks, I thought I had!

DANG3Rv avatar Dec 02 '21 20:12 DANG3Rv

Hi,

First of all, waht a great work. Thank you very much because it's really the tools that missed to manage WSUS...

I have two issues and one suggestion at the end

1. It seems that even if you fixed DeepClean, it still doesn't remove updates that are declined.

2. I added Windows Server 2012 to the $unneededUpdatesbyProductTitles list but it seems to also decline updates for 2012 R2

3. It would be nice I think to add a feature to the optimize daily task to delete declined updates olders than X days, just to make sure the DB is not growing forever for old updates...

I think it's nice to decline old updates, but then they should be once removed from DB, hence suggestion 3 as well as bugfix 1 don't you think ?

Hello, First of all i would like to say thanks to Awarre for his script. I use it since a couple of weeks and it's exactly what we need :).

Concerning point 2, you just have to replace line 724 with this line to fix the problem: if ((($updateProp -eq "ProductTitles") -And ($update.$($updateProp) -eq "$searchString")) -Or (($updateProp -eq "Title") -And ($update.$($updateProp) -match "$searchString"))){

Regards Cz

ConteZer0 avatar May 17 '23 12:05 ConteZer0