Delete all deactivated WSP Solutions on SharePoint

In the past, the Sandbox Solutions were the easiest way to add custom solution added to your SharePoint Classic sites and usually, we can just deactivating the solution and that will not be activated on the SharePoint site anymore but will always be there on the solutions list unless we delete the package.

With the next PowerShell script, we’ll delete all the deactivated sandbox solutions on your SharePoint site. Note that the solutions that are Activated will not be deleted.

Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/contoso" -UseWebLogin

$solutions = Get-PnPListItem -List _catalogs/solutions
foreach($solution in $solutions){
 Write-Host "Solution: "$solution.FieldValues.FileLeafRef " "
 try {
	Remove-PnPListItem -Identity  $solution.FieldValues.ID -List _catalogs/solutions -force -ErrorAction Stop
	Write-Host " Done" -BackgroundColor Green -ForegroundColor Black 
 }
 catch{
  Write-Host "Still Active" -BackgroundColor Red 
  
 }
}

Conclusion

All the Sandbox solution that was deactivated on your SharePoint site are now deleted from the solutions gallery. Note that the solutions that are Activated will not be deleted.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *