The power shell commands to install solutions and activate the features are :
Add-SpSolution
Install-SPSolution
Enable-SPFeature
But what if there are a lot of wsps to be installed and each wsp had two or more features? That is a lot of adding, installing and activating !!!! I was faced with a similar situation recently, so I had written a small script to automate the whole process.
I used an inputs.xml file to define the solutions to be deployed and the features to be activated in each solution.

The install script loops though each of the solution tag , adds it to the solution gallery, installs it either globally or to a web application based on the parameters and then activates it on the relevant site.
## Start Logging
$LogTime = Get-Date -Format dd-MM-yyyy_h-mm
$LogFile = “Log_InstallScript-$LogTime.txt”
start-Transcript -path $LogFile -Force
## Parsing the Input XML
write-host “Parsing the input file…”
[System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument
$file = resolve-path (“Inputs.xml”)
$xd.load($file)
$InstallNode = $xd.selectSingleNode(“/Install”)
$RootWebUrl = $InstallNode.getAttribute(“Url”)
write-host “Deployment Target :” $RootWebUrl
$Solutions = $xd.selectNodes(“/Install/Solution”)
if($Solutions.count -gt 0)
{
foreach($Solution in $Solutions)
{
$SolutionName = $Solution.getAttribute(“Name”)
$SolutionPath = $Solution.GetAttribute(“Path”)
$SolutionType = $Solution.GetAttribute(“Type”)
write-host “Adding solution: ” $SolutionName
Add-SpSolution -LiteralPath “$SolutionPath\$SolutionName”
Start-Sleep -s 15
write-host “Installing solution: “$SolutionName
if($SolutionType -eq “Global”)
{
Install-SPSolution -Identity $SolutionName -GACDeployment -Force
}
else
{
Install-SPSolution -Identity $SolutionName -WebAppliaction $RootWebUrl -GACDeployment -Force
}
Start-Sleep -s 30
$Features = $Solution.SelectNodes(“Feature”)
if($features.count -gt 0)
{
foreach($Feature in $Features)
{
$FeatureName = $Feature.GetAttribute(“Name”)
$FeatureId = $Feature.GetAttribute(“ID”)
$Web = $Feature.GetAttribute(“Web”)
Write-Host “Enabling Feature :” $FeatureName “on ” $RootWebUrl/$Web
Enable-SPFeature -Identity $FeatureId -url “$RootWebUrl/$Web”
}
}
write-host “Completed deploying :” $SolutionName
}
}
else
{
write.host “No solutions found for deployment.”
}
## Stop Logging
Stop-Transcript
Add-PSSnapin Microsoft.sharePoint.PowerShell
## Start Logging
$LogTime = Get-Date -Format dd-MM-yyyy_h-mm
$LogFile = “Log_InstallScript-$LogTime.txt”
start-Transcript -path $LogFile -Force
## Parsing the Input XML
write-host “Parsing the input file…”
[System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument
$file = resolve-path (“Inputs.xml”)
$xd.load($file)
$InstallNode = $xd.selectSingleNode(“/Install”)
$RootWebUrl = $InstallNode.getAttribute(“Url”)
write-host “Deployment Target :” $RootWebUrl
$Solutions = $xd.selectNodes(“/Install/Solution”)
if($Solutions.count -gt 0)
{
for($x=$Solutions.count-1;$x -ge 0; $x–)
{
$Solution = $Solutions[$x]
$Features = $Solution.SelectNodes(“Feature”)
if($features.count -gt 0)
{
for($y=$Features.count-1;$y -ge 0;$y–)
{
$Feature = $Features[$y]
$FeatureName = $Feature.GetAttribute(“Name”)
$FeatureId = $Feature.GetAttribute(“ID”)
$Web = $Feature.GetAttribute(“Web”)
Write-Host “Disabling Feature :” $FeatureName “on ” $RootWebUrl/$Web
Disable-SPFeature -Identity $FeatureId -url “$RootWebUrl/$Web”
}
}
$SolutionName = $Solution.getAttribute(“Name”)
$SolutionPath = $Solution.GetAttribute(“Path”)
$SolutionType = $Solution.GetAttribute(“Type”)
$SolutionTocheck = Get-SPSolution -identity $SolutionName -ErrorAction:SilentlyContinue
if ($SolutionToCheck)
{
if ($SolutionToCheck.Deployed)
{
write-host “Retracting Solution: ” $SolutionName
if ($SolutionToCheck.ContainsWebApplicationResource)
{
Uninstall-SPSolution -identity $SolutionToCheck -allwebapplications -Confirm:$false
}
else
{
Uninstall-SPSolution -identity $SolutionToCheck -Confirm:$false
}
}
while ($SolutionToCheck.Deployed)
{
start-sleep -s 15
write-host “Waiting for Retraction to Complete”
}
start-sleep -s 15
write-host “Deleting Solution: ” $SolutionName
Remove-SPSolution $SolutionToCheck -Confirm:$false
}
}
}
else
{
write.host “No solutions found.”
}
## Stop Logging
Stop-Transcript
Remove-PsSnapin Microsoft.SharePoint.PowerShell

