Sunday, March 31, 2013

Exchange 2007 and 2010 anti-spam automatic installation

Some organizations use the built-in anti-spam feature in Exchange 2007 and 2010.

Content Filter engine is using definitions created by Microsoft and in an ideal world they are downloaded, approved and installed with help of windows update, but for many reason this is not always possible.

I created a small vbscript that uses windows update to search for only Exchange standard antispam updates and automatically install them without doing anything with other updates.

WU_Exchange_AntiSpam.vbs script can easily be scheduled to run with task scheduler.

' search and automatically install Exchange Server standard antispam definitions
' Lasse Pettersson,

Set updateSession = CreateObject("Microsoft.Update.Session")
'Updatetitle to search for
updateTitle = "Microsoft Exchange Server Standard Anti-spam Filter Updates"

WScript.Echo vbCRLF & "Searching for: " & updateTitle & "..."
Set updateSearcher = updateSession.CreateupdateSearcher()

'Search for all software updates, already installed and not installed
Set searchResult = updateSearcher.Search("Type='Software'")
Set updateToInstall = CreateObject("Microsoft.Update.UpdateColl")
updateIsApplicable = False

'Cycle through search results to look for the update title
For i = 0 To searchResult.Updates.Count-1
Set update = searchResult.Updates.Item(i)
If Left(UCase(update.Title),Len(updateTitle)) = UCase(updateTitle) Then
'Update in list of applicable updates
'Determine If it Is already installed Or Not
If update.IsInstalled = False Then
WScript.Echo vbCrlf & "Result: Update applicable, not installed."
updateIsApplicable = True
'Update Is installed so notify user And quit:
WScript.Echo vbCrlf & "Result: Update applicable, already installed."
updateIsApplicable = True
End If
End If

If updateIsApplicable = False Then
WScript.Echo "Result: Update is not applicable to this machine."
End If

'Download update
Set downloader = updateSession.CreateUpdateDownloader()
downloader.Updates = updateToInstall
WScript.Echo vbCrlf & "Downloading..."
Set downloadResult = downloader.Download()
WScript.Echo "Download Result: " & downloadResult.ResultCode

'Install Update
Set installer = updateSession.CreateUpdateInstaller()
WScript.Echo vbCrlf & "Installing..."
installer.Updates = updateToInstall
Set installationResult = installer.Install()

'Output the result of the installation
WScript.Echo "Installation Result: " & installationResult.ResultCode
WScript.Echo "Reboot Required: " & installationResult.RebootRequired

If you run this script manually, use the cscript engine because some text is written and looks better if you don’t use the wscript engine.

1 comment: