Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Performs a series of steps to clear out WSUS:
- - Declines all superseded updates;
- - Uses Invoke-WsusServerCleanup to perform indivdual cleanup tasks in sequence;
- - Runs the SQL optimisation T-SQL script from https://docs.microsoft.com/en-us/troubleshoot/mem/configmgr/reindex-the-wsus-database
- - Restarts WSUS services (stops completely then starts);
- - Restarts IIS (stops completely then restarts);
- #>
- Clear-Host
- # START DECLINE PROCESS
- [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
- Clear-Host
- $script:wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer('<WSUS_SERVER>', $false, '8530')
- $<WSUS_SERVER>
- $unwantedUpdates = $wsus.GetUpdates() | Where-Object {$_.IsDeclined -like 'False' -and $_.IsSuperseded -like 'True'}
- <#$unwantedUpdates.Title
- $unwantedUpdates.Count#>
- ForEach($update in $unwantedUpdates)
- {
- $update.Title
- $update.Decline()
- }
- # STOP DECLINE PROCESS #
- # START CLEAN PROCESS
- Invoke-WsusServerCleanup -CleanupObsoleteComputers
- Invoke-WsusServerCleanup -CleanupObsoleteUpdates
- Invoke-WsusServerCleanup -CleanupUnneededContentFiles
- Invoke-WsusServerCleanup -CompressUpdates
- Invoke-WsusServerCleanup -DeclineExpiredUpdates
- Invoke-WsusServerCleanup -DeclineSupersededUpdates
- # STOP CLEAN PROCESS #
- # START SQL OPTIMISATION PROCESS
- cmd /c 'C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\sqlcmd.exe' -S \\.\pipe\MICROSOFT##WID\tsql\query -E -i C:\Support\Scripts\WSUS\dbBackup\reindexWSUS.sql
- # STOP SQL OPTIMISATION PROCESS #
- # RESTART/STOP WSUS SERVICES
- Restart-WebAppPool WsusPool
- Restart-Service 'MSSQL$MICROSOFT##WID'
- Restart-Service WsusService
- Restart-Service w3logsvc
- Stop-Service W3SVC
- Stop-Service WAS
- Restart-Service wuauserv
- #
- # START WSUS SERVICES
- Start-Service w3logsvc
- Start-Service W3SVC
- Start-Service WAS
- #
- Start-Sleep 20
- Get-Service 'MSSQL$MICROSOFT##WID'
- Get-Service WsusService
- Get-Service w3logsvc
- Get-Service W3SVC
- Get-Service WAS
- Get-Service wuauserv
- Get-WebAppPoolState WsusPool
- # RESTART IIS
- cmd /c iisreset /stop
- cmd /c iisreset /start
- ##
Advertisement
Add Comment
Please, Sign In to add comment