How to Get the List of WSPs (Solutions) Installed in a SharePoint Farm using PowerShell

Sathish Nadarajan
 
Solution Architect
May 16, 2016
 
Rate this article
 
Views
12473

As Part of an analysis, I wanted the List of WSPs installed in my SharePoint farm. To get that, I was about to write a small function in PowerShell Script. The function is as follows.

 #############  Get All The Solutions in the Farm and their deployed WebApplications ############ 
 
 function GetSolution()
 {
     $script:Progress = "1,Entered"
     Write-Host "Entered into GetSolution Method" -ForegroundColor Yellow 
     Add-Content "$ProgressFile" "Entered into GetSolution Method"
     
     # Assign the CSV and XML Output File Paths
     $Solution_XML_Path = $scriptBase + "Reports-$LogTimeAvailableSolutions.xml"
     
     # Create the XML File Tags
     $xmlWriter = New-Object System.XMl.XmlTextWriter($Solution_XML_Path,$Null)
     $xmlWriter.Formatting = 'Indented'
     $xmlWriter.Indentation = 1
     $XmlWriter.IndentChar = "`t"
     $xmlWriter.WriteStartDocument()
     $xmlWriter.WriteComment('Solutions List')
     $xmlWriter.WriteStartElement('Solutions')
     $xmlWriter.WriteEndElement()
     $xmlWriter.WriteEndDocument()
     $xmlWriter.Flush()
     $xmlWriter.Close()
  
     
     # Get All the Solutions
     Add-Content "$ProgressFile" "Gathering All the Solutions from the Farm"
     
     $SolutionCollection = $farm.Solutions
     
     Add-Content "$ProgressFile" "Gathered All the Solutions from the Farm"
     
     if($SolutionCollection.Count -gt 0)
     {
         # Iterate through all the Solutions
         foreach($Solution in $SolutionCollection)
         {
             $tempContent = "Collecting the Information about the Solution : " + $Solution.DisplayName
             Add-Content "$ProgressFile" $tempContent
             
             # Get the deployed web applications
             $SPDeployedWebApps = $Solution.DeployedWebApplications
             
             # Create the Initial Solution Node
             $xmlDoc = [System.Xml.XmlDocument](Get-Content $Solution_XML_Path);
             $solutionNode = $xmlDoc.CreateElement("Solution")
             $xmlDoc.SelectSingleNode("//Solutions").AppendChild($solutionNode)
             $solutionNode.SetAttribute("Name", $Solution.DisplayName)
             
             Add-Content "$ProgressFile" "Iterate through the Installed Web Applications"
             # Iterate through all the Deployed Web Applications
             foreach($WebApplication in $SPDeployedWebApps)
             {
                 # write the output on XML File
                 
                 $webAppNameNode = $solutionNode.AppendChild($xmlDoc.CreateElement("WebApplication"));
                 $webAppNameNode.SetAttribute("Name", $WebApplication.DisplayName)
                 
                 $webAppURLNode = $webAppNameNode.AppendChild($xmlDoc.CreateElement("URL"));
                 $webAppURLTextNode = $webAppURLNode.AppendChild($xmlDoc.CreateTextNode($WebApplication.Url));
                 
                 $webAppDeploymentStateNode = $webAppNameNode.AppendChild($xmlDoc.CreateElement("Deployed"));
                 $webAppDeploymentStateTextNode = $webAppDeploymentStateNode.AppendChild($xmlDoc.CreateTextNode($Solution.DeploymentState));
                 
                 $xmlDoc.Save($Solution_XML_Path) 
             }
         }
      }
      
      Write-Host "Completed GetSolution Method" -ForegroundColor Green 
      Add-Content "$ProgressFile" "Completed GetSolution Method"
      $script:Progress = "1:Success"
      
      Write-Host "Please Find the Output XML file in the Path :" $Solution_XML_Path  -ForegroundColor Green 
 }
 
 ########### End of Method #################
 

Happy Coding,

Sathish Nadarajan.

Category : PowerShell, SharePoint

Author Info

Sathish Nadarajan
 
Solution Architect
 
Rate this article
 
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 15+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business ...read more
 

Leave a comment