Created
March 25, 2016 11:21
-
-
Save Guzzter/a5b7c4392afef2e8fbc4 to your computer and use it in GitHub Desktop.
Some Powershell functions for usage in Tridion machines
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
# Check if script is run with Administrator permissions. If not: stop directly. | |
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` | |
[Security.Principal.WindowsBuiltInRole] "Administrator")) | |
{ | |
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!" | |
Break | |
} | |
function ExtractZipsAndInstall { | |
$startdir = 'GuiExtensions' | |
if (!(Get-Location).Path.EndsWith($startdir)) { | |
write-host (" Error: Script should be started from directory '$startdir', exiting.") -ForegroundColor red | |
exit | |
} | |
Get-ChildItem '.\build\*.zip' | % { | |
& '.\Install-gui-extension.ps1' $_.FullName | |
} | |
} | |
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment