Friday, May 20, 2011

Power Shell Script to add and Install wsp

Hi,

Below is the power shell script to Add and Install wsp.Just you need to update the correct path,name of solution package correctly(which is in bold),copy and paste the below script entirely after updating accordingly.After pressing enter just it will add and install the wsp solution

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
{
Write-Host "Loading SharePoint Powershell Snap-in"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
$SolutionName = "xxxx.wsp"
$SolutionPath = "path" + $SolutionName
write-host "Adding Solution: " $SolutionName
Add-SPSolution -LiteralPath $SolutionPath
$SolutionTocheck = Get-SPSolution -identity $SolutionName
write-host "Deploying Solution: " $SolutionName
if ($SolutionToCheck)
{
if ($SolutionToCheck.ContainsWebapplicationResource)
{
if ($SolutionToCheck.ContainsGlobalAssembly)
{
Install-SPSolution -identity $SolutionToCheck -allwebapplications -GacDeployment
}
else
{
Install-SPSolution -identity $SolutionToCheck -allwebapplications
}
}
else
{
if ($SolutionToCheck.ContainsGlobalAssembly)
{
Install-SPSolution -identity $SolutionToCheck -GacDeployment
}
else
{
Install-SPSolution -identity $SolutionToCheck
}
}
}