2

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
}
  • 1
    AFAIK the identity is also the name of the .wsp file, is it not? So in your code above, the identity would be $wspFIL. – Dylan Cristy Dec 2 '15 at 14:17
3

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
  • Yes, but I actually want to remove and uninstall the solution before deployment, the same way and I can't guarantee the filenames are the same... – Dave Dec 2 '15 at 14:19
  • As @dave says, you can always change the filename of a solution from what it was originally deployed with, but you would want to uninstall / update the existing one (with the old filename). – Robert Lindgren Dec 2 '15 at 14:21
  • Edited my answer, and still looking for a way to automate Id extraction by code. – Evariste Dec 2 '15 at 14:23
  • Finally added the PowerShell code – Evariste Dec 2 '15 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.