Deleting webparts

by dbrs at 2012-09-05 04:46:11

I have a script that does the uninstall of the webpart for me. I deactivate the feature, uninstall the feature, retract the solution and delete the solution, but the webpart still shows up in the gallery. How can I get the webpart out of the gallery with powershell?
by ToddKlindt at 2012-09-07 14:14:52
I don’t know if this is the best way, there here is one way to get it:

$web = get-spweb 'http://www.contoso.com'
$wpg = $web.Lists["Web Part Gallery"]
$wpg.items | select name, id


Of course that first line shouldn’t have all the formatting in it. It’s just a regular get-spweb operation.

That should get you the list of web parts. The SPListItem object has a delete method.

Hope that helps.
tk
by poshoholic at 2012-09-07 14:40:55
Todd, you can get rid of the extra formatting by placing your URL in single quotes inside of the PowerShell block.
by ToddKlindt at 2012-09-07 14:44:14
Thanks.

tk
by dbrs at 2012-09-09 17:13:25
thanks, that works, just needed to filter out the list a bit, I used this
$wpg.items | where {$_.Name -match "ABC.*webpart"} | select name, id