Automated SharePoint 2010 Farm Level Solution Deployment and Retraction Process – Part IV – Using PowerShell Script

Article Series Content

This is fourth and final part of this article series and it provides step by step walk through on how to run deployment and retraction PowerShell script using batch files. Please note that even though this article walks through with batch files, you can still use PowerShell scripts directly to standardize the deployment process without batch files. Follow earliar articles in this series here at Part I, Part II, and Part III.

As I have described in earlier article, one of the assumptions in this script is all the batch files, log files, and WSPs exists in same directory during deployment process. If you are planning to have WSPs and log files in different directories other than batch files, you will have to update the script to make sure it’s not aware of current directory and manually pass in the full path for WSPs and Log files.

Let’s walk through final step by step walk through on how to create batch files and automate the custom SharePoint solution deployment and retraction process.

Step 1 – Prepare for Deployment and Retraction

  • Create Deployment Directory – (e.g. C:\CustomSolutions\Deployment\CustomHomePage)
  • Create Two Batch Files, Each for deployment and retraction (e.g. DeploySolution.bat and RetractSolution.bat)
  • Copy this PowerShell script from Part III to deployment directory (e.g. SPSolutionDeploymentScript.ps1).
  • Copy packaged SharePoint custom solution in same deployment directory (e.g. CustomHomePage.wsp)

Step 2 – Deployment Step

  • Copy following commands in the Deployment batch file (e.g.DeploySolution.bat). You may notice that first step in the batch file is to bypass the PowerShell execution policy. By default, PowerShell execution policy is retracted which would restrict loading PS1 files from the batch files and this step would bypass the PowerShell execution policy. Next step is to call the SPSolutionDeploymentScript.ps1 and passed in all the required parameters.

powershell -Command “& {Set-ExecutionPolicy bypass}” -NoExit
powershell -Command “& {.\SPSolutionDeploymentScript.ps1 -solutionName:CustomHomePage.wsp -webAppUrl:http://sp2010vm:1000 -siteUrl:http://sp2010vm:1000 -siteFeatureNames:@(‘CustomHomePage_CustomHomeWidgets’) -webFeatureNames:@(‘CustomHomePage_CustomHomePage’) -logFileName:DeploySolution.log -action:SD}” -NoExit

pause

 

  • To run the batch file, right click on the batch file and run as administrator.

  • This will run PowerShell script and deploy the solution and activate features on both site collection level and sub sites levels.

Step 3 – Retraction Step

  • Copy following commands for Retract batch file (e.g. RetractSolution.bat)

powershell -Command “& {Set-ExecutionPolicy bypass}” -NoExit
powershell -Command “& {.\SPSolutionDeploymentScript.ps1 -solutionName:CustomHomePage.wsp -webAppUrl:http://sp2010vm:1000 -siteUrl:http://sp2010vm:1000 -siteFeatureNames:@(‘CustomHomePage_CustomHomeWidgets’) -webFeatureNames:@(‘CustomHomePage_CustomHomePage’) -logFileName:RetractSolution.log -action:SR}” -NoExit

pause

  • To run the batch file, right click on the batch file and run as administrator. It will run PowerShell script and retract the solution and deactivate features from both site collection level and sub sites levels.

Transcript Logging
As you would see, both deployment and retraction process would create log files as transcripts. Having log files would be really helpful in the environment where administrators deploys the code in production environment and needed to communicate with developers if deployment or retraction process fails.

Advertisements
This entry was posted in SP2010 Admin PowerShell, SP2010 Dev PowerShell. Bookmark the permalink.