Showing posts with label STSADM. Show all posts
Showing posts with label STSADM. Show all posts

Monday, March 28, 2011

Deploy and Retract .wsp Files using STSADM or PowerShell

As recommended in previous posts on using STSADM; I suggest creating a .cmd file to run the scripts, and save the scripts in a folder.  I am also assuming that you have STSADM added to your variable path.  Don't forget to right click, and run as Administrator!

Deploy with STSADM:
stsadm -o addsolution -filename path\solutionName.wsp
stsadm -o deploysolution -name solutionName.wsp -immediate -allowgacdeployment -force -allcontenturls
stsadm -o execadmsvcjobs
pause
iisreset /noforce

Retract with STSADM:
stsadm -o retractsolution -name solutionName.wsp -immediate -allcontenturls
stsadm -o execadmsvcjobs
pause
stsadm -o deletesolution -name solutionName.wsp -override
pause
iisreset /noforce

Remember, to run the following commands you must have SPShellAdmin permissions (see Add-SPShellAdmin)

Add, Install, Enable, Update, Disable, Uninstall, and Remove Farm or User Solutions (SPUserSolution) with PowerShell:
1) Update lines 1-4 (and line 6 if working with sandboxed solutions).
2) Remove the pound(#) symbol of the command you want to run.

$fileLocation = "C:\Projects\Event Receiver\bin\Debug"
$wspFileName = "Event_Receiver.wsp"
$featureIdentity = "Event Receiver_Feature1"
$url = "http://pc2010.local/"
# Sandboxed Solution Upgrade Name
$toSolutionName = "Event_Receiver_v2.wsp"

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0
$literalPath = $fileLocation + "\" + $wspFileName
Write-Host("Using WSP from: " + $literalPath)

<#
    *****************************
    *       Farm Solutions      *
    *****************************
#>

# Add WSP Solution (http://technet.microsoft.com/en-us/library/ff607552.aspx)
# Write-Host("Adding solution to Farm..."); Add-SPSolution -literalpath $literalPath

# Update Existing WSP Solution (http://technet.microsoft.com/en-us/library/ff607724.aspx)
# Write-Host("Updating solution in Farm..."); Update-SPSolution -identity $wspFileName -literalpath $literalPath -gacdeployment

# Deploy WSP solution to the Farm (http://technet.microsoft.com/en-us/library/ff607534.aspx)
# Write-Host("Deploying solution to the Farm..."); Install-SPSolution -identity $wspFileName -allwebapplications -gacdeployment -force

# Enable an installed feature at the given scope (http://technet.microsoft.com/en-us/library/ff607803.aspx)
# If the feature is a farm feature, no URL is needed
# Write-Host("Enabling Feature..."); Enable-SPFeature -identity $featureIdentity -url $url

# Disable a feature at the given scope (http://technet.microsoft.com/en-us/library/ff607879.aspx)
# If the feature is a farm feature, comment out -URL Parameter
# Write-Host("Disabling Feature..."); Disable-SPFeature -identity $featureIdentity -force -confirm:$false -url $url

# Retract WSP solution from the farm (http://technet.microsoft.com/en-us/library/ff607873.aspx)
# Write-Host("Retracting Solution from Farm..."); Uninstall-SPSolution -identity $wspFileName -confirm:$false

# Delete WSP solution from the farm (http://technet.microsoft.com/en-us/library/ff607748.aspx)
# Write-Host("Deleting solution from Farm..."); Remove-SPSolution -identity $wspFileName -force -confirm:$false

<#
    *****************************
    *       User Solutions      *
    *****************************
#>

# Add sandboxed solution to solution gallery (http://technet.microsoft.com/en-us/library/ff607715.aspx)
# Write-Host("Adding user solution to solution gallery..."); Add-SPUserSolution -LiteralPath $literalPath -Site $url

# Activate the sandboxed solution in a site collection (http://technet.microsoft.com/en-us/library/ff607653.aspx)
# Write-Host("Enabeling sandboxed solution..."); Install-SPUserSolution -identity $wspFileName -Site $url

# Upgrade EXISTING activated sandboxed solution (http://technet.microsoft.com/en-us/library/ff607902.aspx)
# Write-Host("Updating sandboxed solution..."); Update-SPUserSolution -identity $wspFileName -Site $url -ToSolution $toSolutionName

# Deactivate a sandboxed solution from site collection (http://technet.microsoft.com/en-us/library/ff607582.aspx)
# Write-Host("Retracting sandboxed solution..."); Uninstall-SPUserSolution -identity $wspFileName -Site $url -confirm:$false

# Delete a sandboxed solution from site collection (http://technet.microsoft.com/en-us/library/ff607709.aspx)
# Write-Host("Deleting sandboxed solution..."); Remove-SPUserSolution -identity $wspFileName -Site $url -confirm:$false
Update (11/2/2014)
Finally added the ability to Add, Enable, Update, Deactivate, and Remove Sandboxed Solutions (SPUserSolutions).
Added write-host output so that you know what you did...
Update (01/26/2015)
Added a closing parenthesis ")" for installing solution, and fixed some spelling errors

Wednesday, January 19, 2011

Create the STSADM Path Variable for Server 2008

In my last blog I talk about adding the STSADM command path as the first line of your scripts.  However, you can just create a Variable Path that points to STSADM, and never worry about typing out it's location ever again from a command prompt.  Here is how to add a path variable in Server 2008.

  1. Start menu --> right-click Computer --> Properties.
  2. From the Properties window, click Advanced system settings.
  3. Click Environment Variables.
  4. Under System variables, scroll down and select the Path Variable --> Edit.
  5. Add a semi-colon (;) at the end of the last Variable value and paste in the path to STSADM:
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
       

Running STSADM Commands

I know that everyone and their mother has an opinion about how to deal with STSADM commands, so one more opinion won't hurt.
I suggest creating a folder on the C: drive called "Scripts", to store all of the batch (.bat) and command (.cmd) files that you create/run.  It is a lot easier to edit the files in Notepad than it is to retype the whole STSADM command when you make a mistake.  Also, if you blow up your farm, you have a record of all scripts run in case you have to rebuild.
The first thing to do when creating a script for SharePoint 2007 is to add the STSADM path as the first line:
cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN
Then write your STSADM command(s)
The last line of your script should be:
Pause
This will allow you to see the errors or successes without the cmd window closing.
Please remember to right-click the script and Run as Administrator.