SharePoint alerts not working when added through PowerShell,
$url = "https://example.com/delete1"
$listName1 = "Discussion1"
$spWeb = Get-SPWeb $url -ErrorVariable err -ErrorAction SilentlyContinue
if ($err)
{
Write-Host "createing web..."
$spWeb = New-SPWeb -url $url -Template "STS#1" -Name "AlertsTest1" -Description "AlertsTest1"
}
$list = $spWeb.Lists.TryGetList($listName1)
if($list -eq $null)
{
Write-Host "createing list..."
$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DiscussionBoard
$list = $spWeb.Lists.Add($listName1, $listName1, [int]$listTemplate)
}
$SPuser = $spWeb.EnsureUser('domain\user_SCAdmin')
$SPnewAlert = $SPuser.Alerts.Add()
$SPnewAlert.Title = "Powershell Alerts"
$SPnewAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::List
$SPnewAlert.List = $list
$SPnewAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
$SPnewAlert.EventType = [Microsoft.SharePoint.SPEventType]::All
$SPnewAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
$SPnewAlert.Update()
$spWeb.Dispose()
It works when I go to site and add a alert myself using User interface...
Also no alerts are displayed at weburl + /_layouts/15/MySubs.aspx...