SDL Web 8 everyday maintenance script to improve performance

Below script will help you to improve SDL Web 8  / SDL web 8.5 CMS UI performance. Execute this script once or twice a day. This will purge all transactions / restart IIS / restart all services / restart component services. Its ans generic script

#Load Tridion.ContentManager.Automation module
if (Get-Module -ListAvailable -Name Tridion.ContentManager.Automation) {
Import-Module -Name "C:\Program Files (x86)\SDL Web\bin\PowerShellModules\Tridion.ContentManager.Automation\Tridion.ContentManager.Automation.dll" -Verbose
Write-Host "Module Tridion-ContentManager-Automation"
}
else {
Write-Host "Module Tridion-ContentManager-Automation not installed, so skipped loading"
}

#Remove success and failed items from publishing transactions 200 days before from today.
Remove-TcmPublishTransactions -Before (Get-date).AddDays(-10) -Successful -Failed
#Remove messages
Remove-TcmQueueMessages -Queues PublishQueue
Remove-TcmQueueMessages -Queues DeployQueue
Remove-TcmQueueMessages -Queues SearchQueue
Remove-TcmQueueMessages -Queues WorkflowAgentQueue
Remove-TcmQueueMessages -Queues BatchQueue

# Remove batches
Remove-TcmBatches

#To check the status of the indexes befor search index
Get-tcmqueueinfo

#Re-index all publications
Sync-TcmSearchIndex
#To check the status of the indexes
Get-tcmqueueinfo

# Stop.IIS.Tridion.TMS.Services.ps1

stop-service -displayname "IIS Admin Service" -force
stop-service -displayname "World Wide Web Publishing Service"

stop-service -displayname "SDL Web Content Distributor Transport Service" -force
stop-service -displayname "SDL Web Content Manager Batch Processor"
stop-service -displayname "SDL Web Content Manager Publisher"
stop-service -displayname "SDL Web Content Manager Search Host"
stop-service -displayname "SDL Web Content Manager Search Indexer"
stop-service -displayname "SDL Web Content Manager Service Host" -force
stop-service -displayname "SDL Web Content Manager Workflow Agent"
stop-service -displayname "SDL Web Monitoring Service"
stop-service -displayname "SDL Web Translation Manager"
#stop-service -displayname "SDL Web Audience Manager Service"
#stop-service -displayname "SDL Web Audience Manager Synchronization"
#stop-service -displayname "SDL Web Cache Channel Service"
#stop-service -displayname "SDL Web Content Service"
#stop-service -displayname "SDL Web Experience Optimization Management Service"
#stop-service -displayname "SDL Web Experience Optimization Query Service"
#stop-service -displayname "SDL Web Session Preview Service"

#stop-service -displayname "Tridion Translation Manager"
#$CompName="822589-tridcm2.ord.intensive.int"
$comObj = new-object -comobject comadmin.comadmincatalog
#$comObj
#$comObj.connect($env+":"+$CompName)
$comObj.shutdownapplication("SDL Web Content Manager")


# Start.IIS.Tridion.TMS.Services.ps1

start-service -displayname "IIS Admin Service"
start-service -displayname "World Wide Web Publishing Service"

start-service -displayname "SDL Web Content Distributor Transport Service"
start-service -displayname "SDL Web Content Manager Batch Processor"
start-service -displayname "SDL Web Content Manager Publisher"
start-service -displayname "SDL Web Content Manager Search Host"
start-service -displayname "SDL Web Content Manager Search Indexer"
start-service -displayname "SDL Web Content Manager Service Host"
start-service -displayname "SDL Web Content Manager Workflow Agent"
start-service -displayname "SDL Web Monitoring Service"
start-service -displayname "SDL Web Translation Manager"

#start-service -displayname "SDL Web Audience Manager Service"
#start-service -displayname "SDL Web Audience Manager Synchronization"
#start-service -displayname "SDL Web Cache Channel Service"
#start-service -displayname "SDL Web Content Service"
#start-service -displayname "SDL Web Experience Optimization Management Service"
#start-service -displayname "SDL Web Experience Optimization Query Service"
#start-service -displayname "SDL Web Session Preview Service"


$comObj = new-object -comobject comadmin.comadmincatalog
#$comObj.connect($env:COMPUTERNAME)
$comObj.startapplication("SDL Web Content Manager")

#Stop the SMTP Virtual Server
#$SMTP=[adsi]"IIS://localhost/SMTPSVC/1"
#$SMTP.ServerState = 4
#$SMTP.SetInfo()

#Start the SMTP Virtual Server
$SMTP=[adsi]"IIS://localhost/SMTPSVC/1"
$SMTP.ServerState = 2
$SMTP.SetInfo()