How to erase all the updates from WSUS to free space and re-download only necessary updates
WSUS Version used to test: 3.0¹ (Windows Server 2008 R2) and 6.2.9200.22167 (Windows 2012 Standard)
Even using the Server Cleanup Wizard from WSUS, is normal that along the time the WSUS uses too much space.
To solve this problem is possible to use a script that declines updates that are unnecessary, and then, is possible to erase manually all the accumulated updates downloads and redo only the necessary downloads.
First, close the WSUS, and stop the WSUS Service:
net stop wsusservice
Execute this script .ps1 that will decline the unnecessary updates that are superseded.
#Change server name and port number and $True if it is on SSL
$Computer = $env:COMPUTERNAME
[String]$updateServer1 = $Computer
[Boolean]$useSecureConnection = $False
[Int32]$portNumber = 8530
#If you are using WSUS 3.0, probably your portNumber is 80
# Load .NET assembly
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$count = 0
# Connect to WSUS Server
$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer1,$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
In Windows Explorer, navigate to the WSUS Content Folder (Typically in C:\WSUS\WSUSContent).
Erase all the folders and files inside of the folder WSUSContent.
Open the CMD or Powershell, navigate to C:\Program Files\Update Services\Tools
Execute the command:
WSUSUtil.exe RESET
Reset: "Checks that every update metadata row in the database has corresponding update files stored in the file system. If update files are missing or have been corrupted, WSUS downloads the update files again."
Start again the wsusservice
net start wsusservice
After this moment, it will start to check the database and download all the approved updates, and the process can last hours to be ended.
¹ I needed to install the Powershell 4.0 to be able to use the script.
Sources and more information:
https://xenappblog.com/2016/how-to-clean-up-wsus/
https://blogs.technet.microsoft.com/sudheesn/2015/03/24/powershell-script-to-decline-all-superseded-updates-in-wsus/
https://technet.microsoft.com/en-us/library/cc720466(v=ws.10).aspx
https://social.technet.microsoft.com/Forums/windows/en-US/1f5acf3f-2e1e-4aae-9df3-d491f60d63ac/wsus-getadminserver-fails-to-connect-when-run-locally-on-wsus-server?forum=winserverpowershell
Even using the Server Cleanup Wizard from WSUS, is normal that along the time the WSUS uses too much space.
To solve this problem is possible to use a script that declines updates that are unnecessary, and then, is possible to erase manually all the accumulated updates downloads and redo only the necessary downloads.
First, close the WSUS, and stop the WSUS Service:
net stop wsusservice
Execute this script .ps1 that will decline the unnecessary updates that are superseded.
#Change server name and port number and $True if it is on SSL
$Computer = $env:COMPUTERNAME
[String]$updateServer1 = $Computer
[Boolean]$useSecureConnection = $False
[Int32]$portNumber = 8530
#If you are using WSUS 3.0, probably your portNumber is 80
# Load .NET assembly
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$count = 0
# Connect to WSUS Server
$updateServer = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer1,$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
In Windows Explorer, navigate to the WSUS Content Folder (Typically in C:\WSUS\WSUSContent).
Erase all the folders and files inside of the folder WSUSContent.
Open the CMD or Powershell, navigate to C:\Program Files\Update Services\Tools
Execute the command:
WSUSUtil.exe RESET
Reset: "Checks that every update metadata row in the database has corresponding update files stored in the file system. If update files are missing or have been corrupted, WSUS downloads the update files again."
Start again the wsusservice
net start wsusservice
After this moment, it will start to check the database and download all the approved updates, and the process can last hours to be ended.
¹ I needed to install the Powershell 4.0 to be able to use the script.
Sources and more information:
https://xenappblog.com/2016/how-to-clean-up-wsus/
https://blogs.technet.microsoft.com/sudheesn/2015/03/24/powershell-script-to-decline-all-superseded-updates-in-wsus/
https://technet.microsoft.com/en-us/library/cc720466(v=ws.10).aspx
https://social.technet.microsoft.com/Forums/windows/en-US/1f5acf3f-2e1e-4aae-9df3-d491f60d63ac/wsus-getadminserver-fails-to-connect-when-run-locally-on-wsus-server?forum=winserverpowershell
Comentários
Postar um comentário