Pnp-powershell: Uninstall-PnPSolution not working as expected

Created on 15 May 2018  路  2Comments  路  Source: pnp/PnP-PowerShell

Reporting an Issue or Missing Feature

Potential issue with the Uninstall-PnPSolution cmdlet

Expected behavior

I would expect the *.wsp file to be deactivated and uninstalled from the Solutions folder.

Actual behavior

When trying to uninstall a solution, I receive the following error. From what I can tell, it's looking within the design folder and not the solutions one.

Uninstall-PnPSolution : Invalid field name. {33e33eca-7712-4f3d-ab83-6848789fc9b6}  /sites/SiteCollection/_catalogs/design
At line:7 char:1
+ Uninstall-PnPSolution -PackageId $SolutionGuid -PackageName $Solution ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Uninstall-PnPSolution], ServerException
    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Site.UninstallSolution

Steps to reproduce behavior

Connect to a team site using PnPOnline (preferably one with a *.wsp file in the Solutions folder) and run the following code from PowerShell.

#UNINSTALL OLD SOLUTION
$GetSolutionId = Get-PnPListItem -List "_catalogs/solutions" | select -last 1
$SolutionId = $GetSolutionId.FieldValues.SolutionId
$SolutionGuid = ((([GUID]$SolutionId).ToString() |% {"{0:x}" -f $_}) -join '\')
$GetSolutionTitle = Get-PnPListItem -List "_catalogs/solutions" | select -last 1
$SolutionTitle = $GetSolutionTitle.FieldValues.FileLeafRef
Uninstall-PnPSolution -PackageId $SolutionGuid -PackageName $SolutionTitle

Which version of the PnP-PowerShell Cmdlets are you using?

  • [ ] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

ver 2.26.18

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub

Most helpful comment

@kefujino
it automatically adds the -v1.0 by default if you didn't set the Major and Minor versions when adding the pnp solution into the solutions gallery.
There are a few things that needs to be taken into consideration.

a) if you set the version when installing the pnp solution you must add it also when uninstalling the solution else it aparrently doesn't found out.

b) The parameterName passed on the uninstalling function can't have the version because it doesn't find out.

Example:
We added a product with major version 0 and minor version 0 ( default )
The way to remove it was.

    $appName = ($remProd.path -split "-v")[0]
    Uninstall-PnPSolution -PackageId $remProd.id -PackageName $appName -MajorVersion 0

Keep in mind also that information related with the product are not removed ( js , css associated for example ) and you need to remove it somehow.

Also only solutions installed via pnp are removable.

All 2 comments

@StevieBleeds

It seems to following issue is same one.

https://github.com/SharePoint/PnP-PowerShell/issues/598

The Uninstall-PnPSolution command internally uses the DesignPakage class, but it is originally targeted for design packages (not solution packages).

But, we follow to the Design Pakege's naming convention, I confirmed that it works.
(The same error occurred, but I could deactivate and remove .wsp file)

Exsample

NG : TestSolution.wsp
OK : TestSolution-v1.0.wsp

So you add the version in your solution title, and specify the package name excluding "-v1.0" as follows when you run this command.

Uninstall-PnPSolution -PackageId $SolutionGuid -PackageName "TestSolution"

As far as I know, there is a two way.

銉籖ename your package name to like the above sample
銉籛hen you install your solution to Solution Gallery, you use Install-PnPSolution command

Using the Install method of the DesignePakage class automatically gives the version name, so I think that Install-PnPSolution command is also the same behavior.

@kefujino
it automatically adds the -v1.0 by default if you didn't set the Major and Minor versions when adding the pnp solution into the solutions gallery.
There are a few things that needs to be taken into consideration.

a) if you set the version when installing the pnp solution you must add it also when uninstalling the solution else it aparrently doesn't found out.

b) The parameterName passed on the uninstalling function can't have the version because it doesn't find out.

Example:
We added a product with major version 0 and minor version 0 ( default )
The way to remove it was.

    $appName = ($remProd.path -split "-v")[0]
    Uninstall-PnPSolution -PackageId $remProd.id -PackageName $appName -MajorVersion 0

Keep in mind also that information related with the product are not removed ( js , css associated for example ) and you need to remove it somehow.

Also only solutions installed via pnp are removable.

Was this page helpful?
0 / 5 - 0 ratings