如何使用PowerShell从Web部件库中删除Web部件文件(例如abc.webpart)

时间:2013-08-21 16:03:32

标签: sharepoint-2010 sharepoint-2013

即使在禁用和卸载SharePoint功能以及卸载和删除SharePoint解决方案之后,.webpart文件仍会列在“Web部件库”中。

我按以下顺序发出命令:

Disable-SPFeature
Uninstall-SPFeature
Uninstall-SPSolution
Remove-SPSolution

我仍然可以看到.webpart文件正在徘徊。想象一下,我知道Web部件文件名(例如abc.webpart),如何使用SharePoint PowerShell清理它们(完全删除)。

1 个答案:

答案 0 :(得分:0)

这个powershell应该让你开始(它不是生产就绪,但会完成这项工作)

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery = '<Where><Eq><FieldRef Name="FileLeafRef" /><Value Type="Text">abc.webpart</Value></Eq>  </Where>'
$spQuery.Query = $camlQuery

$site = Get-SPSite -Identity "http://site-collection-url"
$webpartgallery = $site.GetCatalog( [Microsoft.SharePoint.SPListTemplateType]::WebPartCatalog)
$webparts = $webpartgallery.GetItems($spQuery)
$webparts[0].Recycle()