Rebuild xDB Index in Azure using PowerShell

Rebuild xDB Index in Azure using PowerShell

Rebuild xDB indexes maybe required every now and then if you notice an issue with XDB or when you migrate your xDB data from another instance. but getting the right access to Azure environment is not always easy if you in a setup where getting access to Kudu explorer.

To overcome this you can use PowerShell script to rebuild without logging into the azure portal or kudu app (you still need publish profile details). The below script will make it happen.

$credPair =  "$('$(Azure.DeployUserName)'):$("$(Azure.DeployPassword)")"
Write-Host $credPair
Write-Host $body
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))
$header = @{ 
    "Authorization" = "Basic $encodedCredentials"
    "Content-type"  = "application/json"
}


$body = (ConvertTo-Json @{ command = 'Sitecore.XConnectSearchIndexer.exe -rr'; dir = 'C:\home\site\wwwroot\App_Data\jobs\continuous\IndexWorker\' })

Invoke-RestMethod $(Azure.xConnectSearchScmUrl)/api/command -Headers $header -Body $body -Method 'POST'

From the above code replace the value of 3 variables

$(Azure.DeployUserName) – Username from publishing profile

$(Azure.DeployPassword) – Password from publishing profile

$(Azure.xConnectSearchScmUrl) kudu url for xconnect search app – if your xconnect app url is https://xconnect.azurewebsites.net then your scm url will be https://xconnect.scm.azurewebsites.net.

Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *