Remove duplicates in Search Results Webpart
asnp "*sh*"
$resultsPage =
"Pages/default.aspx"
$resultsUrl =
"$siteUrl/$resultsPage"
$spweb =
Get-SPWeb $siteUrl
$page =
$spweb.GetFile($resultsPage)
# Check if
the page is checked out to someone if so override the checkout
$bool=$page.CheckedOut
if($bool)
{
$page.UndoCheckOut();
}
# checkout
the Page
$page.CheckOut()
# Get the
web part manager for the page
$webPartManager =
$spweb.GetLimitedWebPartManager($resultsUrl,
[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
# And pull
the web part we want to work on
$webpart =
$webpartmanager.WebParts
| ? { $_.Title -eq 'Latest News'
}
$dataProvider =
ConvertFrom-Json $webpart.DataProviderJSON
$dataProvider.TrimDuplicates = 'True'
$webpart.DataProviderJSON = ConvertTo-Json $dataProvider -Compress
$webpartmanager.SaveChanges($webpart)
$page.CheckIn('Setting the duplicates in LatestNews');
$page.Publish('Duplicates were set in Latest News Webpart');
$spweb.Dispose();