Powershell profile script for starting and stopping SDL Web 8 (a.k.a. Tridion) services
###################################################################################### | |
# SDLWeb8PowerShellProfile.ps1 | |
# Description: Powershell profile script for starting and stopping SDL Web 8 (a.k.a. Tridion) services | |
# Inspired by Tridion2011PowerShellProfile.ps1 from Nuno Mendes (nmendes@sdl.com) and Daniel Iyoyo | |
# Modified by Guus Beltman | |
# Change Date: 22/7/2016 | |
# Product Scope: SDL Web 8 | |
# | |
# Installation instructions: | |
# Open PowerShell and execute the following commands: | |
#> Set-ExecutionPolicy -ExecutionPolicy unrestricted -Force | |
#> new-item -path $profile -itemtype file -force | |
#> notepad $profile | |
# PASTE the contents of this file | |
# Save and Close notepad | |
# Restart PowerShell | |
###################################################################################### | |
if (Get-Module -ListAvailable -Name Tridion-CoreService) { | |
Import-Module Tridion-CoreService | |
Write-Host "Module Tridion-CoreService" | |
} else { | |
Write-Host "Module Tridion-CoreService not installed, so skipped loading" | |
} | |
Set-ExecutionPolicy -ExecutionPolicy unrestricted | |
Set-Alias -name gacutil -value C:\"Program Files (x86)"\"Microsoft SDKs"\Windows\"v7.0A"\bin\gacutil.exe | |
# Retrieve SDL Web 8 services present on the system | |
$services = (Get-Service -DisplayName sdl* | select name) | |
# Welcome message | |
" " | |
"You are now entering PowerShell as : " + $env:Username | |
" " | |
function cc() { | |
write-host ' editprofile() - Open Profile script on notepad ++ ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' ' | |
write-host ' SDLServices() - Display all SDL Web 8 Services ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' ' | |
write-host ' Add-Assembly($assemblyPath) - Add Assembly to the GAC ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' Remove-Assembly($assemblyDisplayName) - Remove Assembly from the GAC ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' Get-AssemblyInfo($assemblyDisplayName) - Display Assembly info with references GAC ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' ' | |
write-host ' StartTDS($name) - Start SDL Web 8 Services by name ' -BackgroundColor black -ForegroundColor green | |
write-host ' StopTDS($name) - Stop SDL Web 8 Services by name ' -BackgroundColor black -ForegroundColor red | |
write-host ' ' | |
write-host ' Start-TServices() [sats] - Start all SDL Web 8 Services ' -BackgroundColor black -ForegroundColor green | |
write-host ' Stop-TServices() [sots] - Stop all SDL Web 8 Services ' -BackgroundColor black -ForegroundColor red | |
write-host ' Restart-Tservices() [rts] - Restart all SDL Web 8 Services ' -BackgroundColor black -ForegroundColor yellow | |
write-host ' ' | |
write-host ' Start-ComPlus() - Start SDL Web 8 COM+ ' -BackgroundColor black -ForegroundColor green | |
write-host ' Stop-ComPlus() - Stop SDL Web 8 COM+ ' -BackgroundColor black -ForegroundColor red | |
write-host ' Restart-ComPlus() - Restart SDL Web 8 COM+ ' -BackgroundColor black -ForegroundColor yellow | |
write-host ' ' | |
write-host ' Start-TcmServiceHost() [sahost] - Start TcmServiceHost ' -BackgroundColor black -ForegroundColor green | |
write-host ' Stop-TcmServiceHost() [sohost] - Stop TcmServiceHost ' -BackgroundColor black -ForegroundColor red | |
write-host ' Restart-TcmServiceHost() [rhost] - Stop TcmServiceHost ' -BackgroundColor black -ForegroundColor yellow | |
write-host ' ' | |
write-host ' AddToGac($assemblyPath) - Add assembly to GAC ' -BackgroundColor black -ForegroundColor magenta | |
write-host ' DeployToIngEventDir($assemblyPath) - Deploy the assembly to ING extension dir ' -BackgroundColor black -ForegroundColor magenta | |
write-host ' BackupSystemConfig - Creates a backup of the SDL Web 8 System Config ' -BackgroundColor black -ForegroundColor magenta | |
write-host ' IncrementGUIModification - Increment GUI Modification nr ' -BackgroundColor black -ForegroundColor magenta | |
write-host ' ' | |
#write-host 'Sign-Profile() - Sign the Script Profile file' -ForegroundColor red | |
} | |
#display the list of available functions | |
cc | |
function editprofile { C:\"Program Files (x86)"\"Notepad++"\notepad++.exe $profile } | |
function SDLServices { | |
write-host '******************* SERVICES STATE *************************' -ForegroundColor green | |
foreach($service in $services) { | |
get-service -name $service.Name | |
} | |
get-service -name 'COMSysApp' | |
get-service -name 'W3SVC' | |
write-host '******************* SERVICES STATE *************************' -ForegroundColor green | |
} | |
function StartTDS($name) { | |
start-service -name $name | |
get-service -name $name | |
} | |
function StopTDS($name) { | |
stop-service -name $name -Force | |
get-service -name $name | |
} | |
function Sots { | |
Stop-TServices | |
} | |
function Stop-TServices { | |
write-host '.... STOPPING SERVICES ....' -BackgroundColor yellow -ForegroundColor black | |
foreach($service in $services) { | |
StopTDS($service.Name) | |
} | |
Stop-ComPlus | |
StopTDS( 'COMSysApp') | |
StopTDS( 'W3SVC') | |
SDLServices | |
} | |
function sats { | |
Start-TServices | |
} | |
function Start-TServices { | |
write-host '.... STARTING SERVICES ....' -BackgroundColor yellow -ForegroundColor black | |
foreach($service in $services) { | |
StartTDS($service.Name) | |
} | |
Start-ComPlus | |
StartTDS('COMSysApp') | |
StartTDS('W3SVC') | |
SDLServices | |
} | |
function rts { | |
Restart-Tservices | |
} | |
function Restart-Tservices { | |
Stop-TServices | |
Start-TServices | |
} | |
function sohost { | |
Stop-TcmServiceHost | |
} | |
function Stop-TcmServiceHost() { | |
write-host '.... STOPPING ComPlus + TcmServiceHos ....' -BackgroundColor red -ForegroundColor black | |
Stop-ComPlus | |
StopTDS('TcmServiceHost') | |
} | |
function sahost { | |
Start-TcmServiceHost | |
} | |
function Start-TcmServiceHost { | |
write-host '.... STARTING ComPlus + TcmServiceHost ....' -BackgroundColor green -ForegroundColor black | |
Start-ComPlus | |
StartTDS('TcmServiceHost') | |
} | |
function rhost { | |
Restart-TcmServiceHost | |
} | |
function Restart-TcmServiceHost() { | |
Stop-TcmServiceHost | |
Start-TcmServiceHost | |
} | |
function Get-AssemblyInfo($name) { | |
gacutil /lr $name | |
} | |
function Add-Assembly($path) { | |
AddToGac($path) | |
#gacutil /i $path | |
} | |
function Remove-Assembly($path) { | |
gacutil /u $path | |
} | |
function Sign-Profile { | |
$cert = @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0] | |
Set-AuthenticodeSignature $profile $cert | |
exit | |
} | |
function Stop-ComPlus() { | |
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog | |
$comAdmin.ShutdownApplication("SDL Web Content Manager") | |
Write-Output "COM Plus Ended" | |
} | |
function Start-ComPlus() { | |
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog | |
$comAdmin.StartApplication("SDL Web Content Manager") | |
Write-Output "COM Plus Started" | |
} | |
function Restart-ComPlus() { | |
Stop-ComPlus | |
Start-ComPlus | |
} | |
function AddToGac($Assembly) { | |
if ( $null -eq ([AppDomain]::CurrentDomain.GetAssemblies() |? { $_.FullName -eq "System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" }) ) { | |
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null | |
} | |
$PublishObject = New-Object System.EnterpriseServices.Internal.Publish | |
if ( -not (Test-Path $Assembly -type Leaf) ) { | |
throw "The assembly '$Assembly' does not exist." | |
} | |
$LoadedAssembly = [System.Reflection.Assembly]::LoadFile($Assembly) | |
if ($LoadedAssembly.GetName().GetPublicKey().Length -eq 0) { | |
throw "The assembly '$Assembly' must be strongly signed." | |
} | |
Write-Verbose "Installing: $Assembly" | |
$PublishObject.GacInstall($Assembly) | |
} | |
function DeployToIngEventDir($Assembly) { | |
$defaultEventSystemDir = "O:\Program Files (x86)\SDL Web 8\extensions\eventsystem\" | |
if ( -not (Test-Path $Assembly -type Leaf) ) { | |
throw "The assembly '$Assembly' does not exist." | |
} | |
sohost | |
write-host '.... Copy assembly to ING location ....' -BackgroundColor black -ForegroundColor magenta | |
cp $Assembly $defaultEventSystemDir | |
sahost | |
} | |
function IncrementGUIModification { | |
$filename = $Env:TRIDION_HOME + '\web\WebUI\WebRoot\Configuration\System.Config' | |
$conf = [xml](gc $filename) | |
$modification = [int]$conf.Configuration.servicemodel.server.modification | |
$modification++ | |
$conf.Configuration.servicemodel.server.modification = [string]$modification | |
write-host "Incremented Configuration.servicemodel.server.modification to $modification" -ForegroundColor yellow | |
$conf.Save($filename) | |
} | |
function ResetService { | |
$comPlusName = "SDL SDL Web 8 Content Manager" | |
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog | |
$tcmServiceHostName = "TcmServiceHost" | |
write-host "Stopping TcmServiceHost " -ForegroundColor yellow | |
stop-service -name $tcmServiceHostName -Force | |
get-service -name $tcmServiceHostName | |
write-host "Stopping COM+" -ForegroundColor yellow | |
$comAdmin.ShutdownApplication($comPlusName) | |
write-host "Starting COM+" -ForegroundColor yellow | |
$comAdmin.StartApplication($comPlusName) | |
write-host "Starting TcmServiceHost " -ForegroundColor yellow | |
start-service -name $tcmServiceHostName | |
get-service -name $tcmServiceHostName | |
write-host "Done" -ForegroundColor green | |
} | |
function CreateTempDirForExportToExtension { | |
if (!(Test-Path "c:\SDL Web 8\temp\")) { | |
write-host "SDL Web 8 temp not found, create it." | |
New-Item -ItemType Directory -Force -Path "c:\SDL Web 8\temp" | Out-null | |
} | |
} | |
function CreateBackupFile([string]$filepath) { | |
if(Test-Path $filepath) | |
{ | |
[string]$directory = [System.IO.Path]::GetDirectoryName($filePath); | |
[string]$strippedFileName = [System.IO.Path]::GetFileNameWithoutExtension($filePath); | |
[string]$extension = [System.IO.Path]::GetExtension($filePath); | |
[string]$newFileName = $strippedFileName + [DateTime]::Now.ToString("yyyyMMdd-HHmmss") + $extension; | |
[string]$newFilePath = [System.IO.Path]::Combine($directory, $newFileName); | |
Copy-Item -LiteralPath $filePath -Destination $newFilePath; | |
if((Test-Path $newFilePath)) { | |
Write-Host "Created backup" $newFilePath | |
}else { | |
Write-Warning ("Failed to create backup " + $newFilePath) | |
Break | |
} | |
}else { | |
Write-Warning ($filepath + " does not exist, exiting") | |
Break | |
} | |
} | |
function BackupSystemConfig() { | |
CreateBackupFile -filepath ($env:TRIDION_HOME + 'web\WebUI\WebRoot\Configuration\System.config') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment