Introduction
Normally, we are uninstall and remove the wsp from farm manually. Here i am sharing powershell script for this
$SPfarm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()
$solution = "SolutionName.wsp";
#Getting solution id
$currentSolution = $SPfarm.get_Solutions() | Where-Object { $_.DisplayName -eq $solution; }
$sol_file = $currentSolution.id
$spSolution = GET-SPSolution -Identity $sol_file
if ($spSolution.ContainsWebApplicationResource)
{
$spSolution | UnInstall-SPSolution -AllWebApplications -Confirm:$false
}
else
{
$spSolution | UnInstall-SPSolution -Confirm:$false
}
do { Start-Sleep -Seconds 1; Write-Host "Waiting for undeployment..." } while ($spSolution.DeploymentState -ne [Microsoft.SharePoint.Administration.SPSolutionDeploymentState]::NotDeployed)
Write-Host "Waiting for timer job to complete. " -ForegroundColor Yellow
Start-Sleep -Seconds 30
# Remove solution from solution store
Remove-SPSolution –Identity $sol_file -confirm: $false
Write-Host "Solution undeployed!" -ForegroundColor Green