Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ?<#
- 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 ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement