Tridion 2011 PowerShell profile
One of the first things I do when configuring a new Tridion server is installing a custom PowerShell profile. This profile gives you easy access to manage all the Tridion services running on the server, including the COM+ Applications.
When configuring Tridion by changing settings in the various configuration files or the Tridion MMC snap-in, Tridion services often need to be restarted for the settings take effect. We all know that manually restarting services from the Component Services panel can be a time consuming process, especially if the order of restarting matters and the Tridion COM+ Application also needs a restart.
The following PowerShell profile contains functions to restart all Tridion related services and components in one go. The script was originally created by Nuno Mendes from SDL Support and I slightly modified it to be able to specify all Tridion services present on the system at the beginning of the script. Installation instructions are included if you're new to PowerShell profiles and want to give it a try. After installing the profile PowerShell will look like this when started:
Let me know if you've got questions, suggestions or other tips & tricks.
###################################################################################### | |
# Tridion2011PowerShellProfile.ps1 | |
# Originally created by Nuno Mendes (nmendes@sdl.com) and Daniel Iyoyo | |
# Modified by Remco Rakers | |
# Change Date: 08/12/2013 | |
# Product Scope: SDL Tridion 2011 (all versions) | |
###################################################################################### | |
###################################################################################### | |
# 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 | |
###################################################################################### | |
Set-ExecutionPolicy -ExecutionPolicy unrestricted | |
Set-Alias -name gacutil -value C:\"Program Files (x86)"\"Microsoft SDKs"\Windows\"v7.0A"\bin\gacutil.exe | |
# Configure Tridion services present on the system | |
$services = @( | |
'TCDTransportService', | |
'TcmPublisher', | |
'TcmSearchHost', | |
'TcmSearchIndexer', | |
'TcmServiceHost', | |
'TCMBCCOM', | |
'TCDmonitor', | |
'TCMWorkflow', | |
'TCDLink', # legacy linking service | |
'TCDWAI', | |
'TCDDeployer', | |
'TCDBroker', | |
'TCDCacheService', | |
'TCMIMPEXP' # Content Porter service | |
) | |
# Welcome message | |
" " | |
"You are now entering PowerShell : " + $env:Username | |
" " | |
Get-Module ñListAvailable | |
" " | |
function cc() { | |
write-host ' notepadpp(filename) - Open file in notepad ++ ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' pro() - Open Profile script on notepad ++ ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' ' | |
write-host ' TServices() - Display all Tridion Services ' -BackgroundColor white -ForegroundColor darkblue | |
write-host ' All-Services() - Display all Tridion 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 Tridion Services by name ' -BackgroundColor black -ForegroundColor green | |
write-host ' StopTDS($name) - Stop Tridion Services by name ' -BackgroundColor black -ForegroundColor red | |
write-host ' ' | |
write-host ' Start-TServices() [sats] - Start all Tridion Services ' -BackgroundColor black -ForegroundColor green | |
write-host ' Stop-TServices() [sots] - Stop all Tridion Services ' -BackgroundColor black -ForegroundColor red | |
write-host ' Restart-Tservices() [rts] - Restart all Tridion Services ' -BackgroundColor black -ForegroundColor yellow | |
write-host ' ' | |
write-host ' Start-ComPlus() - Start Tridion COM+ ' -BackgroundColor black -ForegroundColor green | |
write-host ' Stop-ComPlus() - Stop Tridion COM+ ' -BackgroundColor black -ForegroundColor red | |
write-host ' Restart-ComPlus( - Stop Tridion COM+ ' -BackgroundColor black -ForegroundColor yellow | |
write-host ' ' | |
#write-host 'Sign-Profile() - Sign the Script Profile file' -ForegroundColor red | |
} | |
#display the list of available functions | |
cc | |
function notepadpp($f) { C:\"Program Files (x86)"\"Notepad++"\notepad++.exe $f } | |
function pro { notepadpp $profile } | |
function TServices { | |
#get-service -displayname '*Tridion*' | |
write-host '******************* SERVICES STATE *************************' -ForegroundColor green | |
foreach($service in $services) { | |
get-service -name $service | |
} | |
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 { | |
#stop-service -displayname '*Tridion*' -Force | |
write-host '.... STOPPING SERVICES ....' -BackgroundColor yellow -ForegroundColor black | |
foreach($service in $services) { | |
StopTDS($service) | |
} | |
Stop-ComPlus | |
StopTDS( 'COMSysApp') | |
StopTDS( 'W3SVC') | |
Tservices | |
} | |
function sats { | |
Start-TServices | |
} | |
function Start-TServices { | |
#start-service -name '*Tridion*' | |
write-host '.... STARTING SERVICES ....' -BackgroundColor yellow -ForegroundColor black | |
foreach($service in $services) { | |
StartTDS($service) | |
} | |
Start-ComPlus | |
StartTDS('COMSysApp') | |
StartTDS('W3SVC') | |
TServices | |
} | |
function rts { | |
Restart-Tservices | |
} | |
function Restart-Tservices { | |
#restart-service -displayname '*Tridion*' -Force | |
Stop-TServices | |
Start-TServices | |
} | |
function Get-AssemblyInfo($name) { | |
gacutil /lr $name | |
} | |
function Add-Assembly($path) { | |
AddToGac($path) | |
#gacutil /i $path | |
} | |
function Remove-Assembly($path) { | |
gacutil /u $path | |
} | |
function All-Services { get-service -displayname '*' } | |
function Sign-Profile { | |
$cert = @(Get-ChildItem cert:\CurrentUser\My -codesigning)[0] | |
Set-AuthenticodeSignature $profile $cert | |
exit | |
} | |
function Stop-ComPlus() { | |
$TridionAppName = "SDL Tridion Content Manager" | |
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog | |
$comAdmin.ShutdownApplication($TridionAppName) | |
Write-Output "COM Plus Ended" | |
} | |
function Start-ComPlus() { | |
$TridionAppName = "SDL Tridion Content Manager" | |
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog | |
$comAdmin.StartApplication($TridionAppName) | |
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) | |
} |