Powershell: Is there a way to extract the Identity from a WSP file?
-
06-10-2020 - |
Question
I want to automatically add and install some wsp files. To check if the file is already installed I (think I) need the identity of the solution that I am about to deploy. How can I extract the Identity of the solution out of the WSP file?
foreach ($wspFIL in $solutionsARY) {
$fileNameSTR = $filesDIR + $wspFIL
$identitySTR = getIdentityFromWsp fileNameSTR#... this is what I need
Add-SPSolution -LiteralPath $fileNameSTR
Install-SPSolution -Identity $identitySTR
}
La solution
Actually, you don't need to get the Id of the solution: solutions are identified by their file names (xxxx.wsp) OR their Id.
If a solution with the same file name is already added/deployed, you cannot add another one with the same file name...
[Update 1]
Manually, the Id can be extracted by renaming the .wsp to .cab, extracting the manifest.xml file and open it to find its SolutionId
attribute.
There should be a way to automate this through PowerShell.
[Update 2]
Here's the PowerShell code to automate it:
#Create a temp folder
$tempFolder = "C:\temp"
New-Item -ItemType Directory -Force -Path $tempFolder
# Extract the manifest.xml file from the wsp file
expand $fileNameSTR /f:manifest.xml $tempFolder
# Read the XML file and create namespace
$xml = [xml](Get-Content "$tempFolder\manifest.xml")
$xmlNsManager = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$xmlNsManager.AddNamespace("ns", "http://schemas.microsoft.com/sharepoint/")
# Get the SolutionId attribute of the Solution node
$identitySTR = $xml.SelectSingleNode('//ns:Solution', $xmlNsManager).SolutionId