Home
Manage Your Code
Snippet: Deploy-ExCM.ps1 (PowerShell)
Title: Deploy-ExCM.ps1 Language: PowerShell
Description: Iterative dev and deployment for ExCM Views: 1025
Author: Tony Bierman Date Added: 5/20/2008
Copy Code  
# Deploy-ExCM.ps1
# Iterative dev and deployment for ExCM
# Copyright SharePoint Solutions 2008

Param 
(	
	$SolutionDir = $WorkspaceRootDir + "\ExtranetCollaborationManager2009\" + $VBL_ExCM,
	[switch]$i = $false, # Recycle IIS application pool
	[switch]$a = $false, # copy artifacts
	[switch]$g = $false, # gac dlls
	[switch]$b = $false, # build solution
	[switch]$sadd = $false, # Add Solution"
	[switch]$sdel = $false, # Delete Solution"
	[switch]$sdep = $false, # Deploy Solution"
	[switch]$sret = $false, # Retract Solution"
	[switch]$sup = $false, # Upgrade Solution"
	[switch]$fui = $false, # Uninstall / Install Features"
	[switch]$fa = $false, # Activate Features"
	[switch]$fd = $false, # Deactivate Features"
	[switch]$fda = $false, # Deactivate / Activate Features"
	[switch]$testweb = $false, # Delete and recreat test web
	[switch]$wsp = $false, # build solution package
	[switch]$bcl = $false, # update BCL assemblies to GAC
	[switch]$light = $false, # light deployment -a
	[switch]$heavy = $false, # heavy deployment -b -a -g -bcl -i
	[switch]$spheavy = $false, # heavy deployment -fd -sret -sdel -sadd -sdep -fa
	[switch]$u = $false
)

# Include functions
. "${PowerShellLibDir}\SharedBuildFunctions.ps1"

# Member variables
$TemplateDir = $TwelveHive + "\TEMPLATE"
$TargetName = "SPSolutions.SharePoint.ExCM"

function PrintUsage {
	Write-Output "`nDeploy-ExCM usage information."
	Write-Output "Arguments:"
	Write-Output "`t-i Recycle IIS application pool"
	Write-Output "`t-a Deploy artifacts (xcopy)"
	Write-Output "`t-g Deploy assemblies to GAC"
	Write-Output "`t-b Build solution (devenv)"
	Write-Output "`t-sadd Add Solution"
	Write-Output "`t-sdel Delete Solution"
	Write-Output "`t-sdep Deploy Solution"
	Write-Output "`t-sret Retract Solution"
	Write-Output "`t-sup Upgrade Solution"
	Write-Output "`t-fui Uninstall / Install Features"
	Write-Output "`t-fa Activate Features"
	Write-Output "`t-fd Deactivate Features"
	Write-Output "`t-fda Deactivate / Activate Features"
	Write-Output "`t-bcl Update BCL assemblies to GAC"
	Write-Output "`t-testweb Delete and recreate test web"
	Write-Output "`t-wsp Build WSP package (makecab)"
	Write-Output "`t-light Light deployment -a"
	Write-Output "`t-heavy Heavy deployment -b -a -g -bcl -i"
	Write-Output "`t-spheavy SP Heavy deployment -fd -sret -sdel -sadd -sdep -fa"
	Write-Output "`nExamples:"
	Write-Output "`tdeploy-excm -a -b -i -g"
	Write-Output "`tdeploy-excm -b -g"
	Write-Output "`tdeploy-excm -a -i -g -testweb -fui"
	Write-Output ""
} 

#
# Main
#

Write-Output "`nDeploy-ExCM"
Write-Output "Build and deploy utility script for Extranet Collaboration Manager"

# Print usage
if($u){
	PrintUsage
	exit
}

# Build solution
if($b){
	Try { BuildSolution "${BuildConfig_ExCM}" "${SolutionDir}\ExCM2009.sln" } -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Recycle IIS app pool
if($i){
	Try { RecycleApplicationPool "${AppPool_ExCM}" } -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Deploy artifacts and resx files
if($a){
	Try { DeployArtifactsToTwelveHive "${SolutionDir}\ExCM" } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployResourceToTwelveHive "${SolutionDir}\ExCM\RESOURCES" dagcore.resx
		DeployResourceToTwelveHive "${SolutionDir}\ExCM\RESOURCES" excmcore.resx } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployConfigResourceToTestWebAndTwelveHive "${SolutionDir}\ExCM\RESOURCES" dag.resx "${AppRoot_ExCM}"
		DeployConfigResourceToTestWebAndTwelveHive "${SolutionDir}\ExCM\RESOURCES" excm.resx "${AppRoot_ExCM}" } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# GAC assemblies
if($g){
	Try { DeployAssemblyToGac "${SolutionDir}\ExCM\bin\${BuildConfig_ExCM}" "${TargetName}" } -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Delete and recreate test web
if($testweb){
	Try { 
		&stsadm -o deleteweb -url ${WebUrl_ExCM}
		&stsadm -o createweb -url ${WebUrl_ExCM} -sitetemplate "STS#0" -title "Test Web" 
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Delete solution
if($sdel){
	Try { 
		SolutionDelete "SPSolutions.SharePoint.ExCM.wsp"
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}


# Add solution
if($sadd){
	Try { 
		SolutionAdd "${SolutionDir}\ExCM\bin\${BuildConfig_ExCM}\SPSolutions.SharePoint.ExCM.wsp"
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Retract solution
if($sret){
	Try { 
		SolutionRetract "SPSolutions.SharePoint.ExCM.wsp" ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Deploy solution
if($sdep){
	Try { 
		SolutionDeploy "SPSolutions.SharePoint.ExCM.wsp" ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Upgrade solution
if($sup){
	Try { 
		SolutionUpgrade "${SolutionDir}\ExCM\bin\${BuildConfig_ExCM}\SPSolutions.SharePoint.ExCM.wsp" "SPSolutions.SharePoint.ExCM.wsp"
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Uninstall / Install Features
if($fui){

	Try { 
		FeatureDeactivateByName DagComponents ${WebUrl_ExCM}
		FeatureDeactivateByName DagLists ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		FeatureUninstallByName DagComponents
		FeatureUninstallByName DagLists
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		FeatureInstallByName DagLists
		FeatureInstallByName DagComponents
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		FeatureActivateByName DagLists ${SiteUrl_ExCM}
		FeatureActivateByName DagComponents ${WebUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Deactivate Features
if($fd){

	Try { 
		FeatureDeactivateByName ExCMComponents ${SiteUrl_ExCM}
		FeatureDeactivateByName DagComponents ${WebUrl_ExCM}
		FeatureDeactivateByName DagLists ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Activate Features
if($fa){

	Try { 
		FeatureActivateByName ExCMComponents ${SiteUrl_ExCM}
		FeatureActivateByName DagLists ${SiteUrl_ExCM}
		FeatureActivateByName DagComponents ${WebUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Deactivate / Activate Features
if($fda){

	Try { 
		FeatureDeactivateByName DagComponents ${WebUrl_ExCM}
		FeatureDeactivateByName DagLists ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		FeatureActivateByName DagLists ${SiteUrl_ExCM}
		FeatureActivateByName DagComponents ${WebUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Deploy BCL
if($bcl){
	Try { 
		DeployAssemblyToGac "${SolutionDir}\Dependencies\Assemblies" "SPSolutions.Common"
		DeployAssemblyToGac "${SolutionDir}\Dependencies\Assemblies" "SPSolutions.SharePoint"
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Build .wsp files
if($wsp){
	BuildWsp "${SolutionDir}\ExCM\" "${TargetName}" "${SolutionDir}\ExCM\bin\${BuildConfig_ExCM}\"
}

# Heavy deployment -b -a -g -bcl -i
if($heavy){

	Try { BuildSolution "${BuildConfig_ExCM}" "${SolutionDir}\ExCM2009.sln" } -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { RecycleApplicationPool "${AppPool_ExCM}" } -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployArtifactsToTwelveHive "${SolutionDir}\ExCM" } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployResourceToTwelveHive "${SolutionDir}\ExCM\RESOURCES" dagcore.resx
		DeployResourceToTwelveHive "${SolutionDir}\ExCM\RESOURCES" excmcore.resx } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployConfigResourceToTestWebAndTwelveHive "${SolutionDir}\ExCM\RESOURCES" dag.resx "${AppRoot_ExCM}"
		DeployConfigResourceToTestWebAndTwelveHive "${SolutionDir}\ExCM\RESOURCES" excm.resx "${AppRoot_ExCM}" } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployAssemblyToGac "${SolutionDir}\ExCM\bin\${BuildConfig_ExCM}" "${TargetName}" } -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		DeployAssemblyToGac "${SolutionDir}\Dependencies\Assemblies" "SPSolutions.Common"
		DeployAssemblyToGac "${SolutionDir}\Dependencies\Assemblies" "SPSolutions.SharePoint"
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# Light deployment -a
if($light){

	Try { DeployArtifactsToTwelveHive "${SolutionDir}\ExCM" } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployResourceToTwelveHive "${SolutionDir}\ExCM\RESOURCES" dagcore.resx
		DeployResourceToTwelveHive "${SolutionDir}\ExCM\RESOURCES" excmcore.resx } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { DeployConfigResourceToTestWebAndTwelveHive "${SolutionDir}\ExCM\RESOURCES" dag.resx "${AppRoot_ExCM}"
		DeployConfigResourceToTestWebAndTwelveHive "${SolutionDir}\ExCM\RESOURCES" excm.resx "${AppRoot_ExCM}" } -Catch { 
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}

# SPHeavy deployment -fd -sret -sdel -sadd -sdep -fa
if($spheavy){

	Try { 
		FeatureDeactivateByName ExCMComponents ${WebUrl_ExCM}
		FeatureDeactivateByName DagComponents ${WebUrl_ExCM}
		FeatureDeactivateByName DagLists ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		SolutionRetract "SPSolutions.SharePoint.ExCM.wsp" ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		SolutionDelete "SPSolutions.SharePoint.ExCM.wsp"
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		SolutionAdd "${SolutionDir}\ExCM\bin\${BuildConfig_ExCM}\SPSolutions.SharePoint.ExCM.wsp"
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		SolutionDeploy "SPSolutions.SharePoint.ExCM.wsp" ${SiteUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
	
	Try { 
		FeatureActivateByName ExCMComponents ${SiteUrl_ExCM}
		FeatureActivateByName DagLists ${SiteUrl_ExCM}
		FeatureActivateByName DagComponents ${WebUrl_ExCM}
	} -Catch {
		Write-Error "FATAL ERROR, terminating script execution."
		throw $_
	}
}


Write-Output "`n========== Deploy-ExCM completed ==========`n"