Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Professional SharePoint Solution Deployment with PowerShell


Published on

These are my slides from the ShareCamp2013 in Munich http;//

Whether it is a small or a large SharePoint Project, 2010 or 2013, one-man show or development team, simple single server setup, or complex multiple server farm with staging, on-premise or in the cloud at the end the developed SharePoint solutions have to be installed, activated and updated frequently, even during operation with minimum risk, downtime, reproducible and automated.
Both developers and administrators know the common problems associated with solution deployment and the often very lengthy troubleshooting.
In this session I will talk about standardizing the approach with PowerShell by using the free “SharePoint Solution Deployer” ( which supports all the above scenarios and also documents the whole process in detail.

Published in: Technology
  • Increasing Sex Drive And Getting Harder Erections, Naturally ➤➤
    Are you sure you want to  Yes  No
    Your message goes here

Professional SharePoint Solution Deployment with PowerShell

  1. 1. Matthias EinigSharePoint Architect SharePoint developer since 2005Steria AB, www.steria.comStockholm, Sweden MCSE, MCPD, MCITP MSCA in , SharePoint 2007-2013 SCRUM Master and Product OwnerContact Main Focus:@mattein • Solution Architecture, • Solution Development, • SharePoint ALM, • Solution Quality Assurance
  2. 2. SharePoint deployment always causesproblems when:• More than one developer is in a project• Machines are setup differently• Multiple target farms exist• Configuration of the farm is required• Deployment lacks documentationResources are wasted for troubleshooting
  3. 3. Manual deployment Manual setup of WebApps & Site Collections Manual configuration of farm, service apps, WebApps, etc. Manual teststo verify correct deployment
  4. 4. For each farm For each release On updates/bugfixesDEVTEST ACCEPTANCE PRODUCTION
  5. 5. • Standardize deployment process• Configurable• Extendable/customizable• Supports farm and sandboxed solutions• Checks pre-qrequisites• Supports team development• Supports staging scenarios• Detailed logging
  6. 6. • PowerShell scripts• Standardizes the deployment process• Configure once with XML / deploy to multiple environments• Uses environment specific variables• Optimizes multi-server farm deployment• Runs pre-/post deployment actions on all servers in the farm (i.e restart-service)• Runs custom pre-/post-deployment scripts• Logs everything
  7. 7. Browse tohttp://spsd.codeplex.comand download the latest release.Important!Before unpacking the ZIP file, open the fileproperties and unblock the file!Otherwise all batch and ps1 files have to beunblocked separately.
  8. 8. The easiest way: Environment XML files1. Drop WSPs in /Solutions folder Log files2. Run batch file PS scripts Solution drop folderOr configure a custom environment XML:• When deploying WebApp solutions to Batch files to execute only specific web apps predefined actions• When deploying Sandboxed solutions• Having different deployment urls/input parameters for each environment• Requiring prerequisites to be in place
  9. 9. <SPSD Version=""> <!-- The Configuration node contains general settings which may be reused in several environments --> <Configuration ID="Default"> <!-- The Settings node specifies global deployment settings for theThe environment XML has 3 main sections powershell scripts --> <Settings></Settings> <!-- The Restrictions node restricts the solution deployment1. Configuration process to certain requirements --> <Restrictions></Restrictions> • Settings <!-- The Actions node specifies actions which should run after the deployment, retraction or update process --> <Actions></Actions> • Restrictions </Configuration> • Actions <!-- The Environment node specifies the deployment environment with Variables, PreRequisiteSolutions, Solutions --> <Environment ID="Default"> Environment <!-- The Variables node specifies the variables which will be2. replaced in the entire environment XML file --> <Variables ID="Default"></Variables> • Variables <!-- The PreRequisiteSolutions node specifies which solution should be deployed --> • Prerequisite solutions <PreRequisiteSolutions ID="Default"></PreRequisiteSolutions> <!-- The solutionsSolutions node specifies which solution should be deployed/reatracted/updated --> • Solutions <Solutions ID="Default" Force="true" Overwrite="true"></Solutions> </Environment>3. SiteStructures <!-- The SiteStructures node defines one or multiple site structures which should be deployed or retracted (update command is not changing existing content)--> <SiteStructures ID="Default" AllowRetraction="true"></SiteStructures> </SPSD>
  10. 10. <Settings> <!-- Number of retries when solution deployment fails --> <DeploymentRetries>3</DeploymentRetries> <!-- Number of milliseconds to wait for processes, services --> <DeploymentTimeout>60000</DeploymentTimeout> <!-- Specifies if checks and actions should be run on all servers inSettings configures the farm or only the local server --> <RunOnMultipleServersInFarm>Application</RunOnMultipleServersInFarm> <!-- Number of milliseconds to leave the deployment script windows• Basic settings how SPSD is running open after the deployment --> <WaitAfterDeployment>10000</WaitAfterDeployment> <!-- Use wizards to specify variables -->• Timeouts, retries etc. <DisplayWizards>false</DisplayWizards> <!-- Create a log file in ULS log format -->Note: RunOnMultipleServersInFarm requires PowerShell <CreateULSLogfile>false</CreateULSLogfile> </Settings>Remoting to be enabled on each included server for thedeployment account <!-- The Restrictions node restricts the solution deployment process to certain requirements -->Enable-PSRemoting -Confirm:$false <Restrictions> <!-- Allow deployment of solution binaries to the global assemblyRestrictions defines cache --> <AllowGACDeployment>true</AllowGACDeployment> <!-- Allow the deployment of binaries with code access security (CAS)• What type of solutions are allowed to be policies --> <AllowCASPolicies>true</AllowCASPolicies> deployed (GAC, FullTrustBin, with CAS policies) <!-- Allow the deployment of binaries with full trust, only available in SP2013 -->• Which SharePoint version is required <AllowFullTrustBinDeployment>true</AllowFullTrustBinDeployment> <!-- Minimal version number of the SharePoint installation required to deploy this solution -->• Which SharePoint license is requires <MinimalSharePointVersion></MinimalSharePointVersion> <!-- Minimal SharePoint license to deploy this solution. Valid values: Foundation (default), Standard, Enterprise --> <MinimalSharePointLicense>Foundation</MinimalSharePointLicense> </Restrictions>
  11. 11. <!-- The Actions node specifies actions which should run after the deployment, retraction or update process --> <Actions AfterDeploy="true" AfterRetract="true" AfterUpdate="true"> <!-- Restart SPTimerV4 Service on this/all servers with the Application role in the farm --> <RestartService Name="SPTimerV4" Force="false" /> <!-- Restart SPAdminV4 Service on this/all servers in the farm -->Actions configures what to do <RestartService Name="SPAdminV4" Force="false" /> <!-- Restart SPUserCodeV4 Service on this/all servers in the farm -->• After deployment <RestartService Name="SPUserCodeV4" Force="false" />• After retraction <!-- Perform IIS reset on this/all servers in the farm --> <ResetIIS Force="false" />• After update <!-- Recycles all IIS application pools on this/all servers in the farm <!-- Can be used alternatively to the ResetIIS action -->Note: The “After*” attributes can also be assigned directly <RecycleAppPools All="false" />to every action which overrides the Actions node settings. <!-- Warms up urls after the deployment process --> <!-- The warmup will be executed on this/all servers by using a localPossible Actions are proxy to avoid issues with a load balancer --> <!-- It is required, that the LoopBackCheck is disabled on this/all servers to run this action -->• Restart server <!-- The action will run after all structures are created and the custom deployment tasks are finished --> (name can be any Windows Service Name) <!-- The action is not executed on retraction --> <!-- Optional: AllWebApps="[true|false]" Warms up all SharePoint• Reset IIS WebApplications --> <!-- Optional: AllSites="[true|false]" Warms up all SharePoint SiteCollections -->• Recycle Application Pools <WarmUpUrls AllWebApps="true" AllSites="false"> <!-- You can also specify custom urls which should be hit• Warmup Urls <WarmUp Url="$(SiteUrl)" /> <WarmUp Url="$(SiteUrl)" /> --> </WarmUpUrls> </Actions>
  12. 12. Variables allows to create custom variableswhich can be used anywhere: <!-- The Variables node specifies the variables which will be replaced in the entire environment XML file --> <!-- You can use variables with $(variablename) in the xml file and• In the environment XML file $vars["variablename"] in the CustomTargets.ps1 PowerShell script --> <!-- You can also use system environment variables with• In the CustomTargets.ps1 (see further down) $(env:VARIABLENAME) in the xml file and $vars:VARIABLENAME in PowerShell --> <!-- For a detailed list of ystem environment variables open cmd.exe and type "set“ or "Get-ChildItem env:" in PowerShell--> <!-- Attributes -->The variables <Variables ID="Default"> <Variable Name="UserID">$(env:USERDOMAIN)$(env:USERNAME)</Variable>• Are resolved recursively <Variable Name="WebAppUrl"> http://$(env:COMPUTERNAME).$(env:USERDNSDOMAIN) </Variable>• Can include system environment <Variable Name="SiteUrl">http://$(WebAppUrl)/sites/TestSite</Variable> <Variable Name="LCID">1033</Variable> variables like current user, machine </Variables> name, domain etc.
  13. 13. <!-- The PreRequisiteSolutions node specifies which solution should be deployed --> <!-- before the the deployment/update process is starting (does not apply to retraction)--> <PreRequisiteSolutions ID="Default"> <Solution Name="Solution.GAC.wsp" /> <Solution Name="Solution.WebApp.wsp">Prerequisite solutions defines solutions <WebApplication Url="$(WebAppUrl1)" /> <WebApplication Url="$(WebAppUrl2)" />which have to be deployed in order to start </Solution> <Solution Name="Solution.Sanboxed.wsp">the deployment. <SiteCollection Url="$(SiteUrl1)" /> </Solution> </PreRequisiteSolutions> <!-- The solutions node specifies which solution should be deployed/reatracted/updated --> <!-- If the node is missing or empty all solution files found in theSolutions /Solutions folder --> <!-- of the deployment package will be used as farm solutions on all content urls / globally -->If empty or not existing, all solutions which <Solutions ID="Default" Force="true" Overwrite="true">are found in the /Solutions folder are <!-- If you specify one or more solutions here, only these will be used (instead of all WSPs in the solutions folder) -->deployed either: <!-- The solution file has to be located in the /Solutions folder of the deployment package --> <!-- Attributes are inherited from the solutions node and can be To the Global Assembly Cache or overridden for each solution -->• <Solution Name="Solution.GAC.wsp" /> <Solution Name="Solution.WebApp.wsp" Force="true" Overwrite="true">• To all Content Urls (for bin assemblies) <WebApplication Url="$(WebAppUrl1)" /> <WebApplication Url="$(WebAppUrl2)" />If specified, only the given solutions are </Solution> <Solution Name="Solution.Sandboxed.wsp" Overwrite="true">deployed. <SiteCollection Url="$(SiteUrl1)" /> <SiteCollection Url="$(SiteUrl2)" /> <SiteCollection Url="$(SiteUrl3)" /> </Solution> </Solutions>
  14. 14. <SiteStructures ID="Default"> <SiteStructure AllowRetraction="true"> <WebApplication Name="" Url=""> <SiteCollection Name="Name" Description="" SiteLanguageID="$(LCID)" SiteOwnerID="$(env:CurrenUser)"SiteStructures is currently under SiteDefinitonID="STS#01" RelativeUrl="/">development and will come as a future <Permissions> <Permission User="Visitors" PermissionSet="Read" />feature <Permission User="Contributors" PermissionSet="Contribute" /> </Permissions>It will allow to create <Sites> <Site Name="Subsite" Description="" SiteLanguageID="$(LCID)" SiteDefinitonID="STS#01" RelativeUrl="subsite" /> WebApplications </Sites>• <Lists> <List ListName="List" DisplayName="List" ListTemplate="100">• SiteCollections <Item><Field Name="Title">Value</Field></Item> </List> Sites </Lists>• <Libraries> <Library ListName="Documents" DisplayName="Documents"• ListItems/Pages/Documents ListTemplate="105"> <Files><File SourceFile="Files/File.doc” /></Files> </Library>• Permissions <Library ListName="Pages" DisplayName="Pages" ListTemplate="103">• Navigation items <Pages><Page PageLayout="Article" /></Pages> </Library> </Libraries> </SiteCollection> </WebApplication> </SiteStructure>Note: The sample structure is still in draft status. </SiteStructures>
  15. 15. USERNAME.xml <SPSD Version=""> <Configuration>... </Configuration> <Environment>...</Environment> <SiteStructures />SPSD uses the environment XML file </SPSD>in the following precedence Machinename.xml USERNAME.xml (i.e. MEI.xml) <SPSD Version="">1. <Configuration ID="Default" FilePath="Default.xml" /> <Environment ID="CustomMachine">2. MACHINENAME.xml (i.e. WFE01.xml) <Variables ID="CustomMachine">...</Variables> <PreRequisiteSolutions ID=" CustomMachine ">... <Solutions ID=“Default" FilePath="Default.xml" />3. Default.xml </Environment> <SiteStructures ID="Default" FilePath="Default.xml" /> </SPSD>Every XML node can also be loaded Default.xmlfrom a separate file <SPSD Version=""> <Configuration ID="Default"> <Settings>...</Settings>i.e. to <Restrictions>...</Restrictions> <Actions>...</Actions> </Configuration>• Reuse configuration <Environment ID="Default"> <Variables ID="Default">...</Variables> <PreRequisiteSolutions ID="Default">...• Reuse SiteStructure <Solutions ID="Default">...</Solutions> </Environment> <SiteStructures ID="Default">...</SiteStructures> </SPSD>
  16. 16. CustomTargets.ps1Define custom deployment targets in #region AfterDeploythe “Scripts/CustomTargets.ps1” file. # Desc: use this target to perform operations after a successful deployment function AfterDeploy($vars){Available targets are: # Sample PowerShell commands New-SPSite -Url $vars["SiteUrl"]• Before deployment -OwnerAlias $env:USERDOMAIN$env:USERNAME -Name Test Site -Template STS#0’• After deployment Install-SPFeature -Path [feature name]• Before retraction -Force Enable-SPFeature -Identity [feature name] -Url $vars["SiteUrl"] -Force• After retraction Enable-SPFeature -Identity [feature guid] -Url $vars["SiteUrl"] Before upgrade -Force• }• After upgrade #endregion
  17. 17. SPSD Environment Editor helps to:- Create/edit environment XML files- Reference nodes in other files- Create custom variables with the variable editor- Define environment aware URLs for deployment or warmup tasksNote: Existing files will automatically updated to themost current version of SPSD. Comments in the XMLfile will be lost when saving the file.
  18. 18. WebApplication• Deploy test data based on XML input Site 1 Site 2 • WebApplications • SiteCollections/Sites • Pages/Items SubSite 2 • Permissions • Navigation SubSite 1• Visual Studio Project Template• User input dialogs• Integrated in SPSF (
  19. 19. Where do I get it? Follow us! The SharePoint Code Quality Team Torsten Mandelkow @tmandelkow Matthias Einig @mattein
  20. 20. Download for free at