tsk138 icon

Cleanup-Wsus.ps1

tsk138 | PRO | 03/29/17 01:16:02 PM UTC | 0 ⭐ | 714 👁️ | Never ⏰ | []
PowerShell |

1.98 KB

|

None

|

0 👍

/

0 👎

?<#
Created:     2015-06-10
Version:     1.5
Author :     Peter Lofgren
Twitter:     @LofgrenPeter
Blog   :     http://syscenramblings.wordpress.com
 
Disclaimer:
This script is provided "AS IS" with no warranties, confers no rights and 
is not supported by the author
#>
 
<#
.Synopsis
   Does Cleanup of the WSUS database.
.DESCRIPTION
   Will initiate a WSUS database cleanup and log output to a logfile.
.EXAMPLE
   Cleanup-WSUS.ps1
.EXAMPLE
   Cleanup-WSUS.ps1 -LogFile C:\WSUSLog\Cleanup.log
#>
 
[CmdletBinding(SupportsShouldProcess=$true)]
param (
[Parameter(Mandatory=$false)]
$logFile = "C:\Windows\Temp\Wsus.log"
)
 
Add-Content -Path $logFile -Value "$(get-date) Cleanup starting"
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer() 
$cleanupScope = new-object Microsoft.UpdateServices.Administration.CleanupScope; 
$cleanupScope.DeclineSupersededUpdates = $true        
$cleanupScope.DeclineExpiredUpdates = $true 
$cleanupScope.CleanupObsoleteUpdates = $true 
$cleanupScope.CompressUpdates = $true 
$cleanupScope.CleanupObsoleteComputers = $true 
$cleanupScope.CleanupUnneededContentFiles = $true 
$cleanupManager = $wsus.GetCleanupManager(); 
$Result = ($cleanupManager.PerformCleanup($cleanupScope))
Add-Content -Path $logFile -Value "SupersededUpdatesDeclined: $($Result.SupersededUpdatesDeclined)"
Add-Content -Path $logFile -Value "ExpiredUpdatesDeclined: $($Result.ExpiredUpdatesDeclined)"
Add-Content -Path $logFile -Value "ObsoleteUpdatesDeleted: $($Result.ObsoleteUpdatesDeleted)"
Add-Content -Path $logFile -Value "UpdatesCompressed: $($Result.UpdatesCompressed)"
Add-Content -Path $logFile -Value "ObsolotetComputersDeleted: $($Result.ObsoleteComputersDeleted)"
Add-Content -Path $logFile -Value "DiskSpaceFreed: $($Result.DiskSpaceFreed)"
Add-Content -Path $logFile -Value "$(get-date) Cleanup completed"
Add-Content -Path $logFile -Value ""

Comments