Saturday, March 1, 2014

Update Solution with Powershell

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$SolutionPackageName = "MySolution.wsp"
$SolutionPackagePath = "C:\PowershellSetup\MySolution.wsp"

Write-Host "Checking Solution exist or not..." -foregroundcolor Yellow
$solution = Get-SPSolution | where-object {$_.Name -eq $SolutionPackageName}
if($solution -ne $null)
{
Write-Host "Solution Found & Updating Solution..." -foregroundcolor Green
Update-SPSolution -Identity $SolutionPackageName -LiteralPath $SolutionPackagePath -Local -GACDeployment -Force
Write-Host "Solution Updated..." -foregroundcolor Yellow
}

Write-Host "Solution Updation Complete." -foregroundcolor Green

Install WSP with Powershell

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$SolutionPackageName = "MySolution.wsp"
$SolutionPackagePath = "C:\PowershellSetup\MySolution.wsp"

Write-Host "Checking Solution exist or not..." -foregroundcolor Yellow
$solution = Get-SPSolution | where-object {$_.Name -eq $SolutionPackageName}
if($solution -ne $null)
{
Write-Host "Solution Found..." -foregroundcolor Green
if($solution.Deployed -eq $true)
{
Write-Host "Uninstalling Solution..." -foregroundcolor red
Uninstall-SPSolution -Identity $SolutionPackageName -Local -Confirm:$false
Write-Host "Uninstallation Done..." -foregroundcolor Yellow
}
Write-Host "Removing Solution..." -foregroundcolor red
Remove-SPSolution -Identity $SolutionPackageName -Confirm:$false
Write-Host "Solution Removed..." -foregroundcolor Yellow
}

Write-Host "Adding Solution..." -foregroundcolor red
Add-SPSolution -LiteralPath $SolutionPackagePath
Write-Host "Solution Added..." -foregroundcolor Yellow

Write-Host "Installing Solution..." -foregroundcolor red
Install-SPSolution -Identity $SolutionPackageName -Local -GACDeployment -Force
Write-Host "Solution Installed..." -foregroundcolor Yellow
Write-Host "Deployment Complete." -foregroundcolor Green

Install WSP with Powershell

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

$SolutionPackageName = "MySolution.wsp"
$SolutionPackagePath = "C:\PowershellSetup\MySolution.wsp"

Write-Host "Checking Solution exist or not..." -foregroundcolor Yellow
$solution = Get-SPSolution | where-object {$_.Name -eq $SolutionPackageName}
if($solution -ne $null)
{
Write-Host "Solution Found..." -foregroundcolor Green
if($solution.Deployed -eq $true)
{
Write-Host "Uninstalling Solution..." -foregroundcolor red
Uninstall-SPSolution -Identity $SolutionPackageName -Local -Confirm:$false
Write-Host "Uninstallation Done..." -foregroundcolor Yellow
}
Write-Host "Removing Solution..." -foregroundcolor red
Remove-SPSolution -Identity $SolutionPackageName -Confirm:$false
Write-Host "Solution Removed..." -foregroundcolor Yellow
}

Write-Host "Adding Solution..." -foregroundcolor red
Add-SPSolution -LiteralPath $SolutionPackagePath
Write-Host "Solution Added..." -foregroundcolor Yellow

Write-Host "Installing Solution..." -foregroundcolor red
Install-SPSolution -Identity $SolutionPackageName -Local -GACDeployment -Force
Write-Host "Solution Installed..." -foregroundcolor Yellow
Write-Host "Deployment Complete." -foregroundcolor Green