jhorsman
11/26/2013 - 1:39 PM

Install the Tridion CoreService module. As documented in http://tridion.stackexchange.com/q/3641/88. This script is not stable at all.

Install the Tridion CoreService module. As documented in http://tridion.stackexchange.com/q/3641/88. This script is not stable at all.

$powershellModulePath = $env:UserProfile + "\Documents\WindowsPowerShell\Modules\Tridion-CoreService"
#todo test if path is in $env:PSModulePath http://msdn.microsoft.com/en-us/library/dd878350%28v=vs.85%29.aspx
$powershellClientPath = $powershellModulePath + "\Clients"
Write-Debug ("PowerShell module path: {0}" -f $powershellModulePath)
if(!(Test-Path $powershellModulePath))
{
	$newModuleFolder = New-Item -path $powershellModulePath -type directory
	Write-Debug ("Created new module directory {0}" -f $newModuleFolder.FullName)
}
if(!(Test-Path $powershellClientPath))
{
	$newClientFolder = New-Item -path $powershellClientPath -type directory
	Write-Debug ("Created new client directory {0}" -f $newClientFolder.FullName)
}

if(Get-Module Tridion-CoreService)
{
	Write-Debug "Module Tridion-CoreService already exists"
	Remove-Module Tridion-CoreService
	Write-Debug "Removed module Tridion-CoreService"
}

Copy-Item *.psm1 $powershellModulePath
Copy-Item *.psd1 $powershellModulePath
# @todo prevent copy errors
# how to we figure out if this is writable?
# can we unload the DLLs so that we can deploy them?
Copy-Item "Clients\*.dll" $powershellClientPath   #disable this line and copy manually if DLLs are already exist and in use
Write-Debug ("Copied module files from {0} to {1}" -f ((Get-Item ".\").FullName), ((Get-Item $powershellModulePath).FullName))

Import-Module Tridion-CoreService
Write-Host ("Installed Tridion-CoreService module in {0}" -f (Get-Item $powershellModulePath).FullName)