Deploying your SharePoint 2010 solution with Powershell

That`s right, with SharePoint 2010 you will not only be able to deploy your solutions with PowerShell, it will be more difficult if you did it any other way.

For all of you who are still skeptical check out how easy my SharePoint 2010 WSP deployment script is:

1. First I have a Setup.bat that will call my PowerShell script, here`s what`s inside

@echo off

powershell -Command “& {Set-ExecutionPolicy bypass}” -NoExit

powershell -Command “&{.\Setup.ps1}” -NoExit

pause

2. Now, to Setup.ps1 which is the main set of deployment commands, here is what`s inside:

# define variables for script

$SiteTitle = “My Site Title”

$SiteUrl = “http://mysiteurl”

$SiteTemplate = “MySiteTemplate#0″

# Ensure Microsoft.SharePoint.PowerShell is loaded

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}

if ($snapin -eq $null) {

Write-Host “Loading SharePoint Powershell”

Add-PSSnapin “Microsoft.SharePoint.Powershell”

}

# delete any existing site found at URL

$targetUrl = Get-SPSite | Where-Object {$_.Url -eq $SiteUrl}

if ($targetUrl -ne $null) {

Write-Host “Deleting existing site at” $SiteUrl

Remove-SPSite -Identity $SiteUrl -Confirm:$false

}

Write-Host “Uninstalling existing solution packages”

Uninstall-SPSolution –Identity “My.SharePoint.wsp” -Confirm:$false

Write-Host “Removing existing solution packages”

Remove-SPSolution -Identity “My.SharePoint.wsp” -Confirm:$false

Write-Host “Adding solution packages”

Add-SPSolution -LiteralPath “My.SharePoint.wsp”

Write-Host “Installing solutions”

Install-SPSolution -Identity My.SharePoint.wsp -Local -GACDeployment -force

Write-Host “Creating new site at” $SiteUrl

$NewSite = New-SPSite -URL $SiteUrl -OwnerAlias admin_account_id -Template $SiteTemplate -Name $SiteTitle

$RootWeb = $NewSite.RootWeb

Write-Host “————————————-”

Write-Host $RootWeb.Title ”Site created”

Write-Host “URL:” $RootWeb.Url -foregroundcolor Green

Explore more commands here,

Enjoy!

@echo off
powershell -Command “& {Set-ExecutionPolicy bypass}” -NoExit
powershell -Command “&{.\SetupCinx.ps1}” -NoExit
pause
This entry was posted in sharepoint, sharepoint 2010 and tagged , , , , , , , . Bookmark the permalink.

Comments are closed.