# Quelle/Source: http://www.wsus.de/serverbereinigung2 # UH/08.01.16: Mit Quelle und Englischen Kommentaren teilweise ergänzt # UH/08.01.16: source and some Englisch comments added # WSUS Connection Parameters: [String]$WSUSServer = "FQDN vom WSUS Server / FQDN of WSUS" [Boolean]$useSecureConnection = $False [Int32]$portNumber = 80 [String]$LogFile = "C:\WSUS\MeinLogfile.txt" #Beispiel! [String]$SMTPServer = "IP-Adresse vom SMTP Server / IP address of the SMTP server" # Windows PowerShell example to check 'If File Exists' $FileExists = Test-Path $LogFile If ($FileExists -eq $True) { #Alte Logdatei vorsichtshalber löschen. / Delete old Log File Remove-Item $LogFile } # Cleanup Parameters: # Decline updates that have not been approved for 30 days or more, are not currently needed by any clients, and are superseded by an aproved update. [Boolean]$supersededUpdates = $True # Decline updates that aren't approved and have been expired my Microsoft. [Boolean]$expiredUpdates = $True # Delete updates that are expired and have not been approved for 30 days or more. [Boolean]$obsoleteUpdates = $True # Delete older update revisions that have not been approved for 30 days or more. [Boolean]$compressUpdates = $True # Delete computers that have not contacted the server in 30 days or more. [Boolean]$obsoleteComputers = $False # Delete update files that aren't needed by updates or downstream servers. [Boolean]$unneededContentFiles = $True #EndRegion VARIABLES #Region SCRIPT # Load .NET assembly [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration"); # Connect to WSUS Server $wsusParent = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($WSUSServer,$useSecureConnection,$portNumber); # Log the date first date | out-file -filepath $LogFile -append -noClobber; # Perform Cleanup $WSUSServer | out-file -filepath $LogFile -append -noClobber; $CleanupManager = $wsusParent.GetCleanupManager(); $CleanupScope = New-Object Microsoft.UpdateServices.Administration.CleanupScope($supersededUpdates,$expiredUpdates,$obsoleteUpdates,$compressUpdates,$obsoleteComputers,$unneededContentFiles); $CleanupManager.PerformCleanup($CleanupScope) | out-file -filepath $LogFile -append -noClobber; #EndRegion SCRIPT # Der nachfolgende Teil ist von hier kopiert: http://gallery.technet.microsoft.com/scriptcenter/90ca6976-d441-4a10-89b0-30a7103d55db#content # Following part is copied from: http://gallery.technet.microsoft.com/scriptcenter/90ca6976-d441-4a10-89b0-30a7103d55db#content # Mail the report... $message = new-object Net.Mail.MailMessage $mailer = new-object Net.Mail.SmtpClient($SMTPServer) $message.From = "Absender " $message.To.Add("Empfänger ") $MeinText = "WSUS - Server CleanUp Bericht " + $WSUSServer $message.Subject = $MeinText $message.Body = [string]::join([environment]::NewLine, (get-content $logfile)) $mailer.Send($message) #Logdatei löschen / Delete Logfile Remove-Item $LogFile