Tagged: Office 365

Resetting Office 365 Cloud Search Index

From time to time we need to remove all the items out of the Office 365 search index. There are 3 options:

1. Re-index everything on premises and after the indexing completes delete the content sources to trigger a delete crawl to run. Of course re-indexing everything is not efficient, it takes time and if items have been deleted from the on premises content you still run the risk of missing orphans in the Office 365 search index.

2.  Call Microsoft Office 365 support and raise a ticket to ask for an index purge, something that takes time and again is inefficient for the task at hand.

3. Use DeleteAllCloudHybridSearchContent method of PushTenantManager.

More information on DeleteAllCloudHybridSearchContent method can be found here and here.

That was another page in the Chronicles of SharePoint Bits, happy scripting!

SharePoint Online: Using PowerShell to delete alerts in site/sub sites using CSOM

Metalogix Content Matrix is a great tool to migrate from SharePoint on-premises to the the Cloud. As part of migration to SharePoint Online we had to re-migrate some of the content multiple times. If users had alerts set up on the migrated items, those alerts will trigger as content gets re-migrated. Th prevent flood of the emails to the users we needed to deleted the migrated alerts.
Here is a PowerShell script to delete alerts in SharePoint Online. This PowerShell script will delete all alerts in root web and all sub webs in SharePoint Online site.

####################################################################################################
#
#  Author.......: David Shvartsman
#  Date.........: 09/14/2018
#  Description..: SharePoint Online: Delete alerts in site/sub sites using CSOM
#
####################################################################################################
CLS
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" -ErrorAction Stop
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" -ErrorAction Stop

#use the $AlertsExportFile to store existing Alers
$AlertsExportFile = "C:\temp\Alerts.csv"
if (Test-Path $AlertsExportFile) {
    Remove-Item $AlertsExportFile -Confirm:$false
}

$UserName = Read-Host "Please enter User Name"
$Password = Read-Host "Enter a Password" -AsSecureString
$SiteUrl = Read-Host "Please enter SharePoint Online Site URL"

$credentials= New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Password)

$ctx= New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$ctx.Credentials = $credentials

$web = $ctx.Web
$ctx.Load($web)
$ctx.Load($web.Webs)
$siteUsers=$web.SiteUsers
$ctx.Load($siteUsers)
$siteUsers=$web.SiteUsers
$ctx.Load($siteUsers)
$alerts=$web.Alerts
$ctx.Load($alerts)
$ctx.ExecuteQuery()
Write-Host "Processing $($web.Url)"
#List all Alerts for RootWeb site
if ($alerts.Count -gt 0) {
    $alerts |SELECT @{Label="SiteUrl";Expression={"$($web.Url)"}},AlertFrequency, AlertTime, AlertType, AlwaysNotify, DeliveryChannels, EventType, Filter, ID, UserID, Status | Export-Csv $AlertsExportFile -Append -NoTypeInformation
}
foreach($alert in $alerts) {
	$web.Alerts.DeleteAlert($alert.ID)
	$web.Update()
	$ctx.ExecuteQuery()
}
#enumerate through seub webs
foreach ($webSub in $web.Webs) {
    Write-Host "Processing $($webSub.Url)"
    $alertsSub = $Null
    $ctxSub= New-Object Microsoft.SharePoint.Client.ClientContext($webSub.Url)
    $ctxSub.Credentials = $credentials
    $webSub = $ctxSub.Web
    $ctxSub.Load($webSub)
    $alertsSub=$webSub.Alerts
    $ctxSub.Load($webSub)
    $ctxSub.Load($alertsSub)
    $ctxSub.ExecuteQuery()
    #List all Alerts for each sub web
    if ($alertsSub.Count -gt 0) {
        $alertsSub |SELECT @{Label="SiteUrl";Expression={"$($webSub.Url)"}},AlertFrequency, AlertTime, AlertType, AlwaysNotify, DeliveryChannels, EventType, Filter, ID, UserID, Status | Export-Csv $AlertsExportFile -Append -NoTypeInformation
    }
    foreach($alert in $alertsSub){
	    $webSub.Alerts.DeleteAlert($alert.ID)
	    $webSub.Update()
	    $ctxSub.ExecuteQuery()
    }
}

###################################################################################################

All you will need is re-migrate the alerts and you all set!

That was another page in the Chronicles of SharePoint Bits, happy scripting!