Disable Alerts with Powershell in SharePoint

Powershell Script

In a customer project i have a list, in which we import data from other sources regularly. Each time we import data, the users get an email, cause they configured themselves an alert. The alert-function is pretty good if someone else edit or update the list or its items, but in the case of an import we would like to disable the alerting for the time of import and enable it afterwords again. The import script uses a for-loop to import the items one by one.

So i would like to share my experiences with this case, cause i tried some things which did’nt work as expected.

Step #1: Disable alert for the list

I found this nice post. In this script, there a two functions. One disables the alert and the other enables it. It iterates through each alert on the SPWeb and checks if it is configured for the list in order to enable or disable this. I got it working, but i get the alert emails anyway. I guess that calling the function takes more time, so that the script in the function is executed after the loop is finished. I tried several ways, but still got the alert email.

Step #2: Disable alert at webapplication

In this case you disable of course every alert in the whole webapplication. Which means, that no one get any alerts in this time slot. This has effects on all site collections within in the webapplication. I found the script here. The result is not really helpful, cause i got after running the script again a lot of email alerts.

So what did i wrong?

Well, the scripts are running perfectly. The posts above are correct. My mistake was, that i executed the script in this pseudo way:

Disable Alerts -> Import Data -> Enable Alerts

But the timerjob for email alerts looks for items which are changed in the last two minutes. So i had to add a period of waiting time, before enabling the alerts again. So it should look like this:

Disable Alerts -> Import Data -> Wait 150 seconds -> Enable Alerts

Now it is working. After all i didn’t expect this topic to be so complicated and easy at the same time. But i hope it might help you to save some time:) Cause i didn’t think about this 2minutes frame.

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.

Be the first to comment

Leave a Reply