Monday, April 4, 2011

SharePoint 2010: PowerShell to delete a web part from the gallery

param($Identity = "", $Url = "")

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.WebPartPages")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")


$SPSite = New-Object Microsoft.SharePoint.SPSite($Url)

$SPWeb = $SPSite.OpenWeb()
$WebPartGallery = $SPWeb.Lists["Web Part Gallery"]
$gall = $WebPartGallery.Items select Name
$count = $gall.Count
for ($i =0; $i -lt $count;$i++)
{
if ($gall[$i] -match $Identity)
{
$WebPartGallery.Items.Delete($i)
$SPWeb.Update()
Write-Host "$Identity deleted"
$SPWeb.Dispose()
}
}

2 comments:

lee woo said...

In the social jungle of human existence, there is no feeling of being alive without a sense of identity. See the link below for more info.

#identity
www.ufgop.org

sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


edupdf.org