1

My organisation is migrating from SP2010 to SPO and would like to use PowerShell to migrate the best bets from SP2010 to promoted results in SPO.

I currently have a csv file of promoted results and the URLs I would like them to point to. I want to use PowerShell to import them into my SPO site collection. Please suggest if there are any PowerShell scripts for importing promoted results.

Thank you.

1

Please check if below helps... Ref link

    $siteUrl = "http://sandbox0391"
$resultSourceName = "Local SharePoint Results"

$web = Get-SPWeb $siteUrl
$ssa = Get-SPEnterpriseSearchServiceApplication "SBX Search Service Application 2"
$queryRuleManager = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager($ssa)
$site = Get-SPSite $siteUrl
$searchOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner -ArgumentList  @([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::Ssa,$site.RootWeb)
$searchObjectFilter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchOwner)
$federationManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
$resultSource = $federationManager.GetSourceByName($resultSourceName,$searchOwner)
$queryRules = $queryRuleManager.GetQueryRules($searchObjectFilter)
$promotedResultCollection = $ssa.GetBestBets($searchObjectFilter)

function CreatePromotedResult([string]$title, [string]$url, [string]$description)
{
        Write-Host "Creating Promoted Result .." $title
        $queryRule = $queryRules.CreateQueryRule($title,$null,$null,$true)
        [string[]]$keywords = $title.split(' ')
        $keywords += $title     
        $keywordCondition = $queryRule.QueryConditions.CreateKeywordCondition($keywords,$false)
        $queryAction = $queryRule.CreateQueryAction([Microsoft.Office.Server.Search.Query.Rules.QueryActionType]::AssignBestBet)
        #PromotedResult = BestBet
        $promotedResult = $promotedResultCollection.CreateBestBet($title, $url, $description, $false)
        #Map the best bet to the query action
        $queryAction.BestBetIds.Add($promotedResult.Id);
        #Update the query rule
        $queryRule.Update()
        $queryRule = $null  
        Write-Host "Created Promoted Result for" $title "Finished"      
}

CreatePromotedResult "Benefits" "https://URL.com/Pages/OpenEnrollment.aspx" "Benefits page!"

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.