WSUS Serverbereinigung mit Powershell #2

# WSUS Connection Parameters:
[String]$WSUSServer = „FQDN vom WSUS Server angeben“
[Boolean]$useSecureConnection = $False
[Int32]$portNumber = 8530
[String]$LogFile = „C:\WSUS\MeinLogfile.txt“ #Beispiel!
[String]$SMTPServer = „IP-Adresse vom SMTP Server“

# Windows PowerShell example to check ‚If File Exists‘
$FileExists = Test-Path $LogFile
If ($FileExists -eq $True) {
#Alte Logdatei vorsichtshalber löschen.
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
# Mail the report…
$message = new-object Net.Mail.MailMessage
$mailer = new-object Net.Mail.SmtpClient($SMTPServer)

$message.From = „Absender <Absender@Domain.TLD>“
$message.To.Add(„Empfänger <
Empfänger@Domain.TLD>“)
$MeinText = „WSUS – Server CleanUp Bericht “ + $WSUSServer
$message.Subject = $MeinText
$message.Body = [string]::join([environment]::NewLine, (get-content $logfile))
$mailer.Send($message)

#Logdatei löschen.
Remove-Item $LogFile

Diese Webseite verwendet Cookies. Weitere Informationen

Die Cookie-Einstellungen auf dieser Website sind auf "Cookies zulassen" eingestellt, um das beste Surferlebnis zu ermöglichen. Wenn du diese Website ohne Änderung der Cookie-Einstellungen verwendest oder auf "Akzeptieren" klickst, erklärst du sich damit einverstanden.

Schließen