Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Powershell to delete or update Summary Links in Summary Links Web Part

$
0
0

Hello,

I have 100+ SharePoint sites, and each contains a page called Reports. I need to update this page across all of our sites. The reports pages contain several Summary Links web parts, with several links in each. I need to update and/or delete some of those links.

My script works until #BEGIN Remove Link. Can someone help modify this script so that I can delete these summary links based on their titles? I have heard of using links' order to locate them; however on my sites there are some inconsistency to order in which links are listed.

#TESTING - BEGIN
$URL = "http://SPURL"
$web = Get-SPWeb $URL
write-host "Begin deletion of links on the SummaryLinks webpart from" $URL

$pages = $web.Lists["Pages"];
$pageUrl = "Reports.aspx"

foreach ($page in $pages.Items)
        {
            if ($page -eq $null -or $page.Name -ne $pageUrl)
                {
                continue;
                }

        $webPartCollection = $page.Web.GetWebPartCollection($page.Url,[Microsoft.SharePoint.WebPartPages.Storage]::Shared)

        foreach ($webPart in $webPartCollection)
            {
            $wp =  $webPart -as [Microsoft.SharePoint.WebPartPages.WebPart]
            if ($wp.Title -eq ‘Asset Management’)
                {
                 Write-host "Web Part Found"
                # BEGIN Remove Link

                $link = $wp.SummaryLink.SummaryLinkValue.title
                if ($link.title -eq "AP Plans")
                            {
                            write-host "Deleting..." $wp.title "/" $link.title
                            $wp.SummaryLink.Remove($link) | Out-Null
                            }

                }
             }

                $wp.SummaryLinkValue = $wp.SummaryLinkValue
                $webPartCollection.SaveChanges($wp.StorageKey)
                # END Remove Link

                }
            

Eventually I will need to make my script loop across all of my sites. Right now I just need help on making the find/delete portion work.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>