Redeploying a SharePoint solution package

Posted: 5th October 2011 in Deployment, Powershell, Sharepoint 2010

Okay, before anyone comments on the simplicity of this posting. It merely t allow me to get the script easily in the future.  What’s the purpose of it? It basically retracts a solution and waits until its fully retracted, then deletes it, adds it in again and redeploys it. Not rocket science, but handy. 

#Set up Web Application variable
#Only needed if solution contains Web Application scoped resources

$webApp = "
http://sitetodeployto"

#Set up solution name variable
$solutionName =  "solution.wsp"

#Set up solution file path variable
$filePath = "C:\Deploy51011\" + $solutionName

#Uninstall solution
#Add -WebApplication $webApp if solution contains Web Application scoped resources

Uninstall-SPSolution –Identity $solutionName –WebApplication $webApp  -Confirm:$false

#set up a variable for the solution to allow access to properties
$solution = Get-SPSolution $solutionName

#Wait for solution to be uninstalled
do {Start-Sleep -s 1} while ($solution.Deployed -eq $true)

# add another couple of seconds
Start-Sleep -s 2

#Remove solution from the farm without prompting
Remove-SPSolution $solutionName -Confirm:$false

# add it back in and deploy it
Add-SPSolution –LiteralPath $filePath
Install-SPSolution –Identity $solutionName –WebApplication $webApp –GACDeployment

Hope this saves someone some time Winking smile

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s