0

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!

1

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")) 
    {           

    } 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.