Scheduled Maintenance Script

'----------------------------------------------------------------------------------------------------
' Tridion Maintenance Scheduled Task
' Chris Mills  2008
'----------------------------------------------------------------------------------------------------

On Error Resume Next
Err.Clear
scriptdebug = False
uline = "*"

'Application Variables
DeployerZIPRetentionDays = 7
DeployerUnzippedFoldersRetentionDays = 7
CMSPreviewRetentionDays = 28
CMSUploadRetentionDays = 7
BusinessConnectorAttatchmentRetentionDays = 2
BusinessConnectorFarmSubFolderRetentionDays = 2
PublisherRetentionDays = 7


'Event Constants
EventSUCCESS = 0
EventERROR = 1
EventWARNING = 2
EventINFORMATION = 4

' FSO Constants
ForReading = 1
ForWriting = 2
ForAppending = 8

'Service Constants
DisplayName = 0
StartMode = 1
State = 2



'----------------------------------------------------------------------------------------------------
'Initialise Parameters
'----------------------------------------------------------------------------------------------------
dn = "00.01.02.03.04.05.06.07.08.09.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31"
no = split(dn,".")

'----------------------------------------------------------------------------------------------------
'Tridion Environment Variables
'----------------------------------------------------------------------------------------------------
Set oShell = CreateObject( "WScript.Shell" )
    computername  = oShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    tridionhome   = oShell.ExpandEnvironmentStrings("%TRIDION_HOME%")
    tridionbchome = oShell.ExpandEnvironmentStrings("%TRIDION_BC_HOME%")
Set oShell = Nothing

'----------------------------------------------------------------------------------------------------
'Tridion MMC Snap -In Data
'----------------------------------------------------------------------------------------------------
'Add code to read data from snap-in
'Publisher Settings
publisherrootstoragepath = "D:\Temp"

'General Settings
'Preview Path 
'previewpath = "D:\WWW\Tridion\Preview"
' this is constrcuted from tcmpath & "Preview" by reading IIS

'Temporary Path 
temppath = "C:\Windows\Temp"



appname = split(Wscript.ScriptName,".")(0)

tridiondeployer = False
tcmpath = ""
bcpath = ""
webdavpath = ""

'----------------------------------------------------------------------------------------------------
'Generate LogFile name
'----------------------------------------------------------------------------------------------------
LogFile = tridionhome & "log\" & appname & " " & Year(Date) & no(Month(Date)) & no(Day(Date)) & ".txt"

'----------------------------------------------------------------------------------------------------
'Generate script version time stamp
'----------------------------------------------------------------------------------------------------
Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFile = fso.GetFile(wscript.ScriptFullName)
        lastmod = oFile.DateLastModified
    Set oFile = Nothing
Set fso = Nothing

'----------------------------------------------------------------------------------------------------
'Check IIS configuration on this server to see what Tridion web applications are configured
'----------------------------------------------------------------------------------------------------
strComputer = "." 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftIISv2") 
Set colItems = objWMIService.ExecQuery("SELECT * FROM IIsWebVirtualDirSetting",,48) 
' maybe a where clause Where AppFriendlyName IN(Tridion Content Manager,BCListener,webdav,WFListener)
'then add them to another dictionary perhaps
For Each objItem In colItems 
    'writelog "App Name: " & objItem.AppFriendlyName & " -> Path: " & objItem.Path 
    If objItem.AppFriendlyName = "Tridion Content Manager" Then
        tcmpath = objItem.Path
        previewpath = tcmpath & "Preview"
        uploadpath =  tcmpath & "Upload"
        'tcmrunning = objItem.Started
    End If
    If objItem.AppFriendlyName = "BCListener" Then
        bcpath = objItem.Path
        'bclistenerrunning = objItem.Started
    End If
    If objItem.AppFriendlyName = "webdav" Then
        webdavpath = objItem.Path
        'webdavrunning = objItem.Started
    End If
    If objItem.AppFriendlyName = "WFListener" Then
        WFpath = objItem.Path
        'wflistenerrunning = objItem.Started
    End If
Next

'----------------------------------------------------------------------------------------------------
'Check Tridion Services on this machine
'Initilaise Tridion Services Dictionary
'Tridion services state, running, stoped disabled?
'----------------------------------------------------------------------------------------------------
sComputer     = "."
Dim objTridionServicesDictionary
Set objTridionServicesDictionary = CreateObject("Scripting.Dictionary")
Set cInstances = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
sComputer & "/root/cimv2:Win32_Service").Instances_
' try the where clause "WHERE DisplayName LIKE '%Tridion%'") and remove the test below
For Each oInstance In cInstances
    If  InStr(oInstance.Properties_("DisplayName").Value,"Tridion") > 0 Then
        PropertyArray = Array(oInstance.Properties_("DisplayName").Value, _
		oInstance.Properties_("StartMode").Value, oInstance.Properties_("State").Value)
        objTridionServicesDictionary.Add oInstance.Properties_("Name").Value, PropertyArray
    End If
Next
Set cInstances = Nothing

'----------------------------------------------------------------------------------------------------
' Declare Functions and Subroutines
'----------------------------------------------------------------------------------------------------


'Subroutine to enumerate the services on the current machine
'
'TCDBroker:           Tridion Content Broker
'TCDDeployer:         Tridion Content Deployer
'TCDTransportService: Tridion Content Distributor Transport Service
'TCMBCCOM:            Tridion Content Manager Business Connector
'TCMPublish:          Tridion Content Manager Publisher
'TCMSearch:           Tridion Content Manager Search
'TCMWorkflow:         Tridion Content Manager Workflow Agent
'TMSBounceProcessor:  Tridion Marketing Communication Solution Bounce Processor Service
'TmsMailer:           Tridion Marketing Communication Solution Mailer Service
'TMSSynchService:     Tridion Marketing Communication Solution Contact Synchronization Service
'TmsTrigger:          Tridion Marketing Communication Solution Trigger Service
'
Sub EnumerateTridionServices

    writelogbanner "Tridion Services on this machine:"
    For Each key In objTridionServicesDictionary
        writeloghead "    " & key & ": " & Join(objTridionServicesDictionary.Item(key),", ")
    Next
    writeloghead ""
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to remove Deployer files
'
'----------------------------------------------------------------------------------------------------
Sub CleanDeployerFiles(ConfigFile)
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(ConfigFile) Then
        writeloghead ""
        writeloghead "Content Deployer Folder Maintenance Task"
        writeloghead "Using Deployer Config " & ConfigFile
        Set ConfigXmlDoc = CreateObject("Microsoft.XMLDOM")
        If ConfigXmlDoc.load(ConfigFile) Then
            For Each inode In ConfigXmlDoc.selectNodes("//Deployer/Receivers/FileReceiver[@Location]")
                fpath = inode.getAttribute("Location")
                writeloghead "Delete zipped packages"
                writeloghead "Deleting files from " & fpath
                DeleteFiles fpath & "\", "*.zip,*.xml", DeployerZIPRetentionDays
            Next            
            For Each inode In ConfigXmlDoc.selectNodes("//Deployer/WorkFolder[@Location]")
                fpath = inode.getAttribute("Location")
                writeloghead "Delete unzipped package folders"
                writeloghead "Deleting files from " & fpath
                DeleteFolders fpath & "\", DeployerUnzippedFoldersRetentionDays
            Next
        Else
            writeloghead "Error reading cd_deployer_conf.xml"
        End If    
    Else 
        writeloghead "Error reading cd_deployer_conf.xml" & ConfigFile
    End if
Set fso = Nothing
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to Delete Folders
'----------------------------------------------------------------------------------------------------
Sub DeleteFolders(fpath, keepdays)
    BeforeDate = Date() - keepdays
    count = 0
    writeloghead("")
    Select Case keepdays
        Case 0
            writelog "Deleting All Folders "
        Case 1
            writelog "Deleting folders older than one day old "
        Case Else
            writelog "Deleting folders older than " & keepdays & " days old "
    End Select
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim rootFolder
    Set rootFolder = fso.GetFolder(fpath)
    For Each folder In rootfolder.subFolders
        If folder.DateCreated < BeforeDate Then
        fpath = folder.Path
                    If  scriptdebug Then
                        writelog "Delete Folder " & fpath & " - " & folder.DateCreated
                    Else
                        fso.DeleteFolder fpath
                        If err.number = vbEmpty Then
                            writelog fpath & " deleted."
                            err.clear
                        Else
                            writelog fpath & err.description
                        End If
                    End If
            count = count + 1
        End If
    Next
    writeloghead ""
    If count = 1 Then
        writeloghead count & " folder deleted "
    Else
        writeloghead count & " folders deleted "
    End If
    writeloghead ""
    Set fso = Nothing
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to Delete Files
'----------------------------------------------------------------------------------------------------
Sub DeleteFiles(fpath, ftypes, keepdays)
    ' ftypes is in the form  "*.txt,*.doc"  "*.zip;*.xml" or "*.*"
    If len(ftypes) = 0 Then
        ftypes = "*.*"
    End If
    If Instr(ftypes,"*.*") > 0 Then
        ftypes = "*.*"    
    End If
    
    BeforeDate = Date() - keepdays
    count = 0
    writeloghead("")
    Select Case keepdays
        Case 0
            writeloghead "Deleting " & ftypes
        Case 1
            writeloghead "Deleting " & ftypes & " older than one day old "
        Case Else
            writeloghead "Deleting " & ftypes & " older than " & keepdays & " days old "
    End Select
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim rootFolder
    Set rootFolder = fso.GetFolder(fpath)
    For Each file In rootfolder.Files
        If file.DateCreated < BeforeDate Then
            fpath = file.Path
            If ftypes = "*.*" Then
                'writelog "Delete File " & fpath & " - " & file.DateCreated
                    If  scriptdebug Then
                        writelog "Delete File " & fpath & " - " & file.DateCreated
                    Else
                        fso.DeleteFile fpath
                        If err.number = vbEmpty Then
                            writelog fpath & " deleted."
                            err.clear
                        Else
                            writelog fpath & err.description
                        End If
                    End If
            Else 
                If Instr(ftypes,fso.GetExtensionName(file.Path)) > 0 Then
                    fpath = file.Path
                    If  scriptdebug Then
                        writelog "Delete File " & fpath & " - " & file.DateCreated
                    Else
                        fso.DeleteFile fpath
                        If err.number = vbEmpty Then
                            writelog fpath & " deleted."
                            err.clear
                        Else
                            writelog fpath & err.description
                        End If
                    End If
                End If
            End if
            count = count + 1
        End If
    Next
    writeloghead ""
    If count = 1 Then
        writeloghead count & " file deleted "
    Else
        writeloghead count & " files deleted "
    End If
    writeloghead ""
    Set fso = Nothing
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to write debug info to the log file
'----------------------------------------------------------------------------------------------------
Sub writedebug(LogMessage)
    if scriptdebug Then
        writelog("DEBUG: " & LogMessage)
    End If
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to write to the log file with timestamp
'----------------------------------------------------------------------------------------------------
Sub writelog(LogMessage)
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set LogFileObject = FileSystemObject.OpenTextFile(LogFile, ForAppending, True) 
        Message = time() & " " & computername & " " & LogMessage
        LogFileObject.WriteLine(Message)
        LogFileObject.Close
    
    Set LogFileObject = Nothing
    Set FileSystemObject = Nothing 
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to write to the log file without timestamp
'----------------------------------------------------------------------------------------------------
Sub writeloghead(LogMessage)
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set LogFileObject = FileSystemObject.OpenTextFile(LogFile, ForAppending, True) 
        LogFileObject.WriteLine(LogMessage)
        LogFileObject.Close
    
    Set LogFileObject = Nothing
    Set FileSystemObject = Nothing 
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to write to the log file 
'----------------------------------------------------------------------------------------------------
Sub writelogbanner(LogMessage)
    Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set LogFileObject = FileSystemObject.OpenTextFile(LogFile, ForAppending, True) 
        LogMessage = "* " & LogMessage & " *"
        LogFileObject.WriteLine("")
        LogFileObject.WriteLine(string(len(LogMessage),"*"))
        LogFileObject.WriteLine(LogMessage)
        LogFileObject.WriteLine(string(len(LogMessage),"*"))
        LogFileObject.Close
    
    Set LogFileObject = Nothing
    Set FileSystemObject = Nothing 
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to clear Tridion CMS files
'     Deletes Files from the Preview folder
'    Deletes Files from the Upload folder
'----------------------------------------------------------------------------------------------------
Sub DoCMSTasks()
    'Is Tridion CMS configured on this machine?
    '--------------------------------------------------------
    If tridionhome = "%TRIDION_HOME%" Then
        writeloghead "Tridion is not configured for this machine"
    Else
        'writelog tridionhome 
        If tcmpath = "" Then
            writeloghead "Tridion Content Manager is not on this machine"
            writeloghead ""
        Else
            writeloghead "Tridion Content Manager Path is " & tcmpath
            writeloghead ""
            writeloghead "Preview File Folder Maintenance Task"
            writeloghead "Delete files from " & previewpath 
            DeleteFiles previewpath, "*.*", CMSPreviewRetentionDays 
            writeloghead ""
            writeloghead "Uploaded Files Maintenance Task"
            writeloghead "Delete files from " & uploadpath
            DeleteFiles uploadpath, "*.*", CMSUploadRetentionDays
        End If
    End If
End Sub

'----------------------------------------------------------------------------------------------------
' SubRoutine to Delete Business Connector Files
'    Deletes files from Attachements folder
'    Deletes files from each Work\Farm folder
'----------------------------------------------------------------------------------------------------
Sub DoBusinessConnectorTasks()
    ' Is Tridion Business Connector Configured for this machine?
    '-----------------------------------------------------------------------------
    writelog ""
    If tridionbchome = "%TRIDION_BC_HOME%" Then
        writeloghead "Tridion Business Connector is not configured for this machine"
    Else
        'writelog tridionbchome 
            If bcpath = "" Then
            writeloghead "Business Connector is not on this machine"
            writeloghead ""
        Else
            writeloghead ""
            writeloghead "Business Connector Maintenance Task"
            writeloghead ""
            writeloghead "Deleting Business Connector Attachments"
            writeloghead ""
            DeleteFiles tridionbchome & "\attachments" , "*.*", _
			BusinessConnectorAttatchmentRetentionDays
            ' Business Connector Farms
            Set fso = CreateObject("Scripting.FileSystemObject")
            Dim bcFarms
            Set bcFarms = fso.GetFolder(tridionbchome & "\work")
            For Each folder In bcFarms.subFolders
                writeloghead ""
                writeloghead  "Delete Business Connector SubFolders from Farm [" & folder.Name & "]"
                DeleteFolders tridionbchome & "\work\" & folder.Name, _ 
				BusinessConnectorFarmSubFolderRetentionDays
            Next
            Set fso = Nothing
        End If
    End If
End Sub

'----------------------------------------------------------------------------------------------------
' Subroutine to Clean up Deployer files
'    Deletes files from single and Multiple instanced deployer
'----------------------------------------------------------------------------------------------------
Sub DoDeployerTasks()
    'Is Tridion Deployer configured?
    '----------------------------------------
    'Is  Single instance Tridion Deployer configured for this machine?
    '------------------------------------------------------------------------------------
    ConfigFile = tridionhome & "config\cd_deployer_conf.xml"
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(ConfigFile) Then
        tridiondeployer = true
        writeloghead "Single instance Tridion Deployer is configured on this machine"
        writeloghead ""
        CleanDeployerFiles ConfigFile
    End If
    Set fso = Nothing

    ' Is multi instance Deployer configured for this machine
    '-----------------------------------------------------------------------
    ConfigFile = tridionhome & "config\cd_instances_conf.xml"
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(ConfigFile) Then    
        tridiondeployer = true
        writeloghead "Multiple instanced Tridion Deployer is configured for this machine"
        writelog ""
        Set ConfigXmlDoc = CreateObject("Microsoft.XMLDOM")
        If ConfigXmlDoc.load(ConfigFile) Then
            For Each inode In ConfigXmlDoc.selectNodes("//Instances/Instance[@ConfigurationLocation]")
                cpath = inode.getAttribute("ConfigurationLocation")
                CleanDeployerFiles cpath & "\cd_deployer_conf.xml"
            Next
        Else
        writeloghead "Error reading cd_instances_conf.xml"
        writeloghead ""
        End If
        
    End if
    Set fso = Nothing

    If not tridiondeployer Then
        writeloghead "Tridion Deployer is not configured for this machine"
    End if
    writeloghead ""
    writeloghead " Done" 
End Sub




Sub DoPublisherTasks

    writeloghead "Restart Publisher"
    RestartPublisher
    
    writeloghead "Publisher Root storage path Folder Maintenance Task"
    writeloghead "Delete files from " & publisherrootstoragepath 
    DeleteFolders publisherrootstoragepath, PublisherRetentionDays
        
End Sub

'----------------------------------------------------------------------------------------------------
' Subroutine to restart the publisher service
'----------------------------------------------------------------------------------------------------
Sub RestartPublisher

    strCommand = "net stop ""Tridion Content Manager Publisher"""

    Set WshShell = WScript.CreateObject("WScript.Shell") 

    Set oExec = WshShell.Exec(strCommand)

    Do While oExec.Status = 0
         WScript.Sleep 100
    Loop

    If oExec.ExitCode <> 0 Then
        WshShell.LogEvent EventERROR , strCommand & " failed"
        writeloghead strCommand & " failed"
    Else
        'WshShell.LogEvent EventSUCCESS, strCommand & " succeeded"
        writelog strCommand & " succeeded"
    End If

    Set oExec = Nothing


    strCommand = "net start ""Tridion Content Manager Publisher"""

    Set oExec = WshShell.Exec(strCommand)

    Do While oExec.Status = 0
         WScript.Sleep 100
    Loop

    If oExec.ExitCode <> 0 Then
        WshShell.LogEvent EventERROR , strCommand & " failed"
        writeloghead strCommand & " failed"
    Else
        'WshShell.LogEvent EventSUCCESS, strCommand & " succeeded"
        writelog strCommand & " succeeded"
    End If

    Set oExec = Nothing
    
    Set WshShell = Nothing
End Sub











'----------------------------------------------------------------------------------------------------
'2    Application Server Maintenance Tasks
'    2.1    Transport Service Folder Maintenance Task
'    2.2    Content Deployer Folder Maintenance Task
'    2.3    Business Connector Maintenance Task
'    2.4    Preview File Folder Maintenance Task
'    2.5    Temporary File Folder Maintenance Task
'    2.6    Uploaded Files Maintenance Task
'    2.7    Verity Search Collection Optimization Task
'    2.8    Verity Search Collection Cleanup Task
'    2.9    Disk Maintenance Task
'    2.10    Log File Maintenance Task
'    2.11    Restart IIS Maintenance Task
'
'----------------------------------------------------------------------------------------------------
writeloghead "Application: " & appname
writeloghead "Application Version timestamp: " & lastmod
writeloghead "Executed on server " & computername & " at " & Now()
writeloghead ""
writeloghead "Settings:"
writeloghead "    Deployer ZIP Retention Days = " & DeployerZIPRetentionDays
writeloghead "    Deployer Unzipped Folders Retention Days = " & _
DeployerUnzippedFoldersRetentionDays
writeloghead "    CMS Preview Retention Days = " & CMSPreviewRetentionDays
writeloghead "    CMS Upload Retention Days = " & CMSUploadRetentionDays
writeloghead "    Business Connector Attatchment Retention Days = " & _
BusinessConnectorAttatchmentRetentionDays
writeloghead "    Business Connector Farm SubFolder Retention Days = " & _ 
BusinessConnectorFarmSubFolderRetentionDays
writeloghead "    Publisher Folder Retention Days = " & PublisherRetentionDays
writeloghead ""
If scriptdebug Then
    writelogbanner " Debug Mode - Files are not actually deleted "
End If

EnumerateTridionServices


writedebug "Is Tridion Content Manager Running on this machine?"
    If len(tcmpath) > 0 Then
        writelogbanner "Tridion Content Manager is Running"
        writeloghead "Starting Tridion Content Manager Maintenance Tasks"
        DoCMSTasks
    End If

writedebug "Is BCListener Running on this Machine?"
    If len(bcpath) > 0 Then
        writelogbanner "BCListener is Running"
        writeloghead "No BCListener Maintenance Tasks Defined"
        End If

writedebug "Is Webdav running on this machine?"
    If len(webdavpath) > 0 Then
        writelogbanner "Webdav is Running"
        writeloghead "No Webdav Maintenance Tasks Defined"
        End If

writedebug "Is WFListener running on this machine"
    If len(WFpath) > 0 Then
        writelogbanner "WFListener is Running"
        writeloghead "No WFListener Maintenance Tasks Defined"
        End If

writedebug "Is Tridion Broker Service Running on this machine?"    
    If objTridionServicesDictionary.Exists("TCDBroker") Then
        If Instr(objTridionServicesDictionary.Item("TCDBroker")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TCDBroker")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TCDBroker")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion Deployer Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TCDDeployer") Then
        If Instr(objTridionServicesDictionary.Item("TCDDeployer")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TCDDeployer")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TCDDeployer")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                DoDeployerTasks
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion Transport Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TCDTransportService") Then
        If Instr(objTridionServicesDictionary.Item("TCDTransportService")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TCDTransportService")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TCDTransportService")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion Business Connector Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TCMBCCOM") Then
        If Instr(objTridionServicesDictionary.Item("TCMBCCOM")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TCMBCCOM")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TCMBCCOM")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                DoBusinessConnectorTasks
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion Publisher Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TCMPublish") Then
        If Instr(objTridionServicesDictionary.Item("TCMPublish")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TCMPublish")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TCMPublish")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                DoPublisherTasks
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion Search Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TCMSearch") Then
        If Instr(objTridionServicesDictionary.Item("TCMSearch")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TCMSearch")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TCMSearch")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion Workflow Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TCMWorkflow") Then
        If Instr(objTridionServicesDictionary.Item("TCMWorkflow")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TCMWorkflow")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TCMWorkflow")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion TMCS Bounce Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TMSBounceProcessor") Then
        If Instr(objTridionServicesDictionary.Item("TMSBounceProcessor")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TMSBounceProcessor")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TMSBounceProcessor")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion TMCS Mailer Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TmsMailer") Then
        If Instr(objTridionServicesDictionary.Item("TmsMailer")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TmsMailer")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TmsMailer")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion TMCS Synch Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TMSSynchService") Then
        If Instr(objTridionServicesDictionary.Item("TMSSynchService")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TMSSynchService")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TMSSynchService")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If

writedebug "Is Tridion TMCS Trigger Service Running on this machine?"
    If objTridionServicesDictionary.Exists("TmsTrigger") Then
        If Instr(objTridionServicesDictionary.Item("TmsTrigger")(StartMode),"Auto") > 0 Then
            writelogbanner objTridionServicesDictionary.Item("TmsTrigger")(DisplayName) 
            If Instr(objTridionServicesDictionary.Item("TmsTrigger")(State),"Running") > 0 Then
                writeloghead "Service is Running"
                writeloghead "No Maintenance Tasks Defined"
            Else
                writeloghead "!!! Service is not Running !!!"
            End If
        End If
    End If
    
writedebug "Wrap up with Error Report"
Set WshShell = WScript.CreateObject("WScript.Shell")
    If err.number = 0  Then
        WshShell.LogEvent EventSUCCESS, "Tridion Maintenance Tasks completed"
        writeloghead "Tridion Maintenance Tasks completed"
    Else
        WshShell.LogEvent EventERROR, "Tridion Maintenance Tasks completed with errors see logfile " & _
		LogFile & " for details"
        writeloghead "Tridion Maintenance Tasks completed with errors"
        writeloghead Err.Description
        writeloghead Err.Source
    End If
    
Set WshShell = Nothing
Set objTridionServicesDictionary = Nothing

My Tridion Newsletters

SDL Tridion Nominate your MVP Candidate

Sign up and get a newsletter when new Tridion stuff is added to the site

Nominate

SDL Tridion Nominate your MVP Candidate

If you find the content of this page useful, please nominate me for the SDL Tridion MVP award.


Created: Thursday 27th May 2010 11:17 PM
Last Modified: Wednesday 30th June 2010 8:21 PM LinkedIn link: View Chris Mills' profile on LinkedIn
Valid XHTML 1.0! Valid CSS! Level A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0