Skip to content

Instantly share code, notes, and snippets.

@remcorakers
Last active December 30, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remcorakers/7856718 to your computer and use it in GitHub Desktop.
Save remcorakers/7856718 to your computer and use it in GitHub Desktop.
Tridion 2011 PowerShell profile to quickly manage your Tridion services and COM+ Applications from PowerShell. See http://remcorakers.nl/tridion-2011-powershell-profile/ for more information.
######################################################################################
# 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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment