Adding and Deploying Solutions with PowerShell in SharePoint 2010
Visual Studio 2010 makes it really easy to add and deploy solutions
when you are developing (the F5 experience), but you may eventually want to deploy those
solution packages elsewhere then on your development machine. We can still use the stsadm tool, but that
is effectively considered deprecated now in favor of PowerShell.
To get started with PowerShell, run the SharePoint 2010 Management
Console located in your Microsoft SharePoint 2010 Products folder on
your start menu. This automatically loads the
Microsoft.SharePoint.PowerShell snappin so that we can execute
SharePoint commands.

[code:xml]
Add-SPSolution c:\codefolder\SharePointSolution.wsp
Install-SPSolution –Identity SharePointSolution.wsp –WebApplication http://yoursharepointurl -GACDeployment
Update-SPSolution –Identity SharePointSolution.wsp –LiteralPath c:\codefolder\SharePointSolution.wsp –GACDeployment
Uninstall-SPSolution –Identity SharePointSolution.wsp –WebApplication http://yoursharepointurl
Remove-SPSolution –Identity SharePointSolution.wsp
Also cool is getting your SharePoint version by using Powershell
function global:Get-SPFarm
{
return [Microsoft.SharePoint.Administration.SPFarm]::Local
}
$farm = Get-SPFarm
$farm.BuildVersion
The result looks like
Major Minor Build Revision
----- ----- ----- --------
14 0 4536 1000
An unexpected error has occurred - SharePoint Error Page
Lot of course participants of my development courses ask me how to fix the error: An unexpected error has occurred.
If you find nothing in the SharePoint Log you can modify the web.config
<SafeMode MaxControls="200" CallStack="true">
<customErrors mode="Off"/>
You will no longer see the "An unexpected error has occurred" error page and instead you get a lovely ’standard ASP.Net error page’ with the stack trace and everything! It is a best practice to do this on you're development environment. Don't forget to switch it on production!
Stsadm backup and restore scripts
Backup a sitecollection
ECHO ON
SET SITECOLURL="mysitecollectionurl"
SET FILENAME="mybackup.bak"
SET STSADM="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm"
REM ----- Execute Site Collection Backup -----
%STSADM% -o backup -url %SITECOLURL% -filename %FILENAME%
%STSADM% -o execadmsvcjobs
pause
Restore a sitecollection
ECHO ON
SET SITECOLURL="mysitecollectionurl"
SET FILENAME="mybackup.bak"
SET STSADM="C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin\stsadm"
REM ----- Execute Site Collection Restore -----
%STSADM% -o restore -url %SITECOLURL% -filename %FILENAME%
%STSADM% -o execadmsvcjobs
pause
Deployment Batch File
Since a lot of developers use the SharePoint Solution Installer to install Windows Solution Packages (.WSP-files) the stsadm tool is manually used as well for soldution deployment and feature activation. The next .bat file could be used for general deployment using the stsadm.exe tool.
[code:c#]
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm.exe"
@SET URL="http://mysharepointurl"
@SET WSPNAME="mysolution.wsp"
@SET FEATURENAME="myfeature"
%STSADM% -o deactivatefeature -name %FEATURENAME% -url %URL% -force
%STSADM% -o uninstallfeature -name %FEATURENAME% -force
%STSADM% -o retractsolution -name %WSPNAME% -url %URL% -local
%STSADM% -o deletesolution -name %WSPNAME% -override
%STSADM% -o addsolution -filename %WSPNAME%
%STSADM% -o deploysolution -name %WSPNAME% -url %URL% -local -allowGacDeployment
%STSADM% -o installfeature -name %FEATURENAME% -force
%STSADM% -o activatefeature -name %FEATURENAME% -url %URL% -force
iisreset /noforce
pause
[/code]