Disable email notifications in SharePoint 2010

Out of the box in SharePoint 2010 all users who have a profile are also defaulted to having email notifications set to "on".   This might make sense in a small scale implementation but for my customer that was unacceptable.  I created a powershell script that iterates through the user profiles and turns the notifications off.  This script is similar to ones I've posted before for working with the user profile however it uses different fields.  The SharePoint field is called SPS-EmailOptin. This field disables both SharePoint and NewsGator emails.

Of course in future releases these field names might change so you should verify before using this script.  In my case this was SharePoint 2010 October CU and NewsGator Social Sites 1.2.2419.

#Load the SharePoint snap-in
Add-PsSnapinMicrosoft.SharePoint.PowerShell;

#Load the SharePoint assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server");
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles");

#Specify the MySite URL
$MySiteUrl="https://sharepoint.vallery.net/";

#Get the server context for the profile manager
$site=Get-SPSite$MySiteUrl;
$ServerContext=Get-SPServiceContext$site;
$UPManager=new-objectMicrosoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);

#Count variables$ucount=0;
$enumProfiles=$UPManager.GetEnumerator();
"Total User Profiles available:"+$UPManager.Count
$count=0;

#Loop through the profile entries and update the property
#Recieve Instant Notifications - NGAllowMetaEmail (bool)
#24 Hour Digest Email - NGReceiveDigestEmail (bool)
#RSS NewsFeed Email - NGAllowRssEmail (bool)
#SharePoint Notification emails - SPS-EmailOptin (int)
#This field has 3 values one for each email type
foreach ($oUserin$enumProfiles)
{
    $count=$count+1;
    $u=$oUser.Item("Accountname");
    Write-Output"($count):  Setting values for $u";

    $oUser["NGAllowMetaEmail"].Value =$false;
    $oUser["NGReceiveDigestEmail"].Value =$false;
    $oUser["NGAllowRssEmail"].Value =$false;
    $oUser["SPS-EmailOptin"].Value =111;

    $oUser.Commit();
}

#Dispose of site object
$site.Dispose();

Comments

  • Anonymous
    October 17, 2013
    In order to enable it back i found the solution ie in the above script we have to set it to "0" $oUser["SPS-EmailOptin"].Value =0; How to disable  for the new users?? Quick reply's on this is highly appreciated.... :-) Thanks,

  • Anonymous
    October 29, 2013
    Hi Sandy - for new users you'll need to run the job on a regular basis.   You could implement this as a scheduled task or timer job.