Monday, December 22, 2014

Automate Deployments with PowerShell

I created and enhanced some PowerShell script code snippets for the purpose of fully automating any given SharePoint .WSP artifact deployment

Usual steps for a clean SharePoint deployment as follows:

DisableSPFeature(Disable-SPFeature cmdlet)

Disables a SharePoint Feature at the given scope. If the scope of the Feature is the farm, the URL is not needed. Otherwise, provide the URL at which this Feature is to be deactivated.

clip_image001

Usage: DisableSPFeature($CRMWebPartsFeatureId, $False)

UninstallSPFeature(Uninstall-SPFeature cmdlet)

Removes the specified feature definition from the collection of feature definitions in the farm.

clip_image002

Usage: UninstallSPFeature($CRMWebPartsFeatureId)

UninstallSPSolution($CRMWebPartsSolutionName, $False)

Retracts a deployed SharePoint solution.

clip_image003

Usage: UninstallSPSolution($CRMWebPartsSolutionName, $False)

RemoveSPSolution(Remove-SPSolution cmdlet)

Removes a SharePoint solution from a farm.

clip_image004

Usage: RemoveSPSolution($CRMWebPartsSolutionName)

AddSPSolution(Add-SPSolution cmdlet)

Adds a SharePoint solution package to the farm.

clip_image005

Usage: AddSPSolution($CRMWebPartsSolutionPath)

InstallSPSolution(Install-SPSolution cmdlet)

Deploys an installed SharePoint solution in the farm.

clip_image006

Usage: InstallSPSolution($CRMWebPartsSolutionName, $False)

EnableSPFeature(Enable-SPFeature cmdlet)

Enables an installed SharePoint Feature at the given scope.

clip_image007

Usage: EnableSPFeature($CRMWebPartsFeatureId, $False)

WaitForJobTimerToFinish (The Get-SPTimerJob & Start-Sleep cmdlet)

Reads a specified timer job, timer jobs of a specified type, or timer jobs defined for a specified scope. If no parameters are specified, this returns all timer job definitions for the farm. We will validate the state of the job in a while loop until null (finished) returned. Otherwise suspends the activity in a script or session for the specified period of time in our case 2 seconds.

clip_image008

Usage: WaitForJobToFinish

Please find the fully deployment script. Modify as need to fit your deployment.