Scripts > WSUS Serverbereinigung mit Powershell #1


Wahrscheinlich haben Sie schon mal auf Ihrem WSUS Server den Assistenten für die Serverbereinigung ausgeführt.
Er entfernt alte und ersetzte Updates und Computer, die seit mehr als 30 Tagen keinen Statusbericht erstellt haben.

Wäre es nicht schön, eine solche Serverbereinigung automatisch (z.B. jeden Monat) durchführen zu lassen?

Zu schade, das es dafür bisher kein Kommandozeilen-Tool gibt.
Mit Powershell ist dies möglich!


#Region VARIABLES  

# WSUS Connection Parameters: [String]$updateServer = $args[0]
[Boolean]$useSecureConnection = $False [Int32]$portNumber = 80  

# 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 = $True
# 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
$Wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer($updateServer,$useSecureConnection,$portNumber)  

# Perform Cleanup $CleanupManager = $Wsus.GetCleanupManager()
$CleanupScope = New-Object Microsoft.UpdateServices.Administration.CleanupScope $supersededUpdates,$expiredUpdates,$obsoleteUpdates,$compressUpdates,$obsoleteComputers,$unneededContentFiles) $CleanupManager.PerformCleanup($CleanupScope)
 
 
#EndRegion SCRIPT

 

@echo off
set log=c:\wsus\wsus-cleanup.log
set cleanupscript=c:\wsus\WSUS-Serverbereinigung.ps1
set wsus-server-01=Servername.Domain.xxx
set wsus-server-02=Servername.Domain.xxx
set wsus-server-03=Servername.Domain.xxx
set wsus-server-04=Servername.Domain.xxx

echo. >> "%log%"
echo ############################################################ >> "%log%"
echo. >> "%log%"
echo. >> "%log%"

echo Cleanup Report %wsus-server-01% on %date%: >> "%log%"
echo ------------------------------------------------------------ >> "%log%"
"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" "%cleanupscript%" %wsus-server-01% >> "%log%"

echo. >> "%log%" echo Cleanup Report %wsus-server-02% on %date%: >> "%log%"
echo ------------------------------------------------------------ >> "%log%"
"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" "%cleanupscript%" %wsus-server-02% >> "%log%"
 
echo. >> "%log" echo Cleanup Report %wsus-server-03% on %date%: >> "%log%"
echo ------------------------------------------------------------ >> "%log%"
"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" "%cleanupscript%" %wsus-server-03% >> "%log%"
 
echo. >> "%log%" echo Cleanup Report %wsus-server-04% on %date%: >> "%log%"
echo ------------------------------------------------------------ >> "%log%"
"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" "%cleanupscript%" %wsus-server-04% >> "%log%"

Download: WSUS-Serverbereinigung.txt (umbenennen in.ps1)
                        wsus-cleanup.txt (umbenennen in.bat)
 

 

Hinweis:  Sollten Sie bei der Ausführung des Scripts Probleme haben, lesen Sie bitte folgenden Artikel: http://www.gmusoft.de/information/windows/WindowsPowerShell.htm

Happy scheduling!