Question

I get null returned when I run this code

$web = Get-SPWeb "http://siteurl"
$webPartGallery = $web.Lists["Web Part Gallery"]
$webpart=$webPartGallery.Items | ? { $_.Title -eq "webpartname"} #returns null

I check my Web part gallery there are many webparts but this code returns null for me. What is it that I am doing wrong?

Thanks!

Was it helpful?

Solution

Try below code:

$spSiteCollection = Get-SPWeb "http://siteurl"         
$wpCatlog =[Microsoft.SharePoint.SPListTemplateType]::WebPartCatalog 
$spList = $spSiteCollection.GetCatalog([Microsoft.SharePoint.SPListTemplateType]::WebPartCatalog)         


foreach ($spItem in $spList.Items) 
{             
    if($spItem.Title.Contains("webpartname")) 
    {           

    } 
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top