Created
March 25, 2016 11:28
-
-
Save Guzzter/baed0ba462e04e61a1f4 to your computer and use it in GitHub Desktop.
My own version of the Powershell profile for managing Tridion 2011/2013
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################################################### | |
# Tridion2011PowerShellProfile.ps1 | |
# Originally created by Nuno Mendes (nmendes@sdl.com) and Daniel Iyoyo | |
# Modified by Guus Beltman | |
# Change Date: 19/12/2015 | |
# Product Scope: SDL Tridion 2011 and 2013 (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 | |
###################################################################################### | |
Import-Module Tridion-CoreService | |
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 ' 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 ' BackupTridionSystemConfig - Creates a backup of the Tridion 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 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 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 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) | |
} | |
function DeployToIngEventDir($Assembly) { | |
$defaultEventSystemDir = "O:\Program Files (x86)\Tridion\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 Tridion 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 UpdateViewStagingAndLiveUrls { | |
$viewstagliveconf = $Env:TRIDION_HOME + '\GuiExtensions\ViewInStagingAndLive\Editor\Configuration\ViewInStagingAndLive.config' | |
if ((Test-Path $viewstagliveconf)) { | |
$conf = [xml](gc $viewstagliveconf) | |
write-host "Update staging url to" $stagingurl -ForegroundColor yellow | |
($conf.Configuration.settings.customconfiguration.clientconfiguration.staging.add | where { $_.key -eq 'tcm:0-162-1' }).value = $stagingurl | |
write-host "Update live url to" $liveurl -ForegroundColor yellow | |
($conf.Configuration.settings.customconfiguration.clientconfiguration.live.add | where { $_.key -eq 'tcm:0-162-1' }).value = $liveurl | |
$conf.Save($viewstagliveconf) | |
} | |
} | |
function CreateTempDirForExportToExtension { | |
if (!(Test-Path "c:\tridion\temp\")) { | |
write-host "Tridion temp not found, create it." | |
New-Item -ItemType Directory -Force -Path "c:\tridion\temp" | Out-null | |
} | |
} | |
#example: CreateBackupFile -filepath ($env:TRIDION_HOME + 'web\WebUI\WebRoot\Configuration\System.config') | |
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 BackupTridionSystemConfig() { | |
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