How to See Who Has Unsubscribed from Auto-News Digest Emails

Auto-news digest is a useful feature in Microsoft 365 that helps keep users in the loop. It does so by sending personalised email updates to the user, showing trending news articles that they have not yet read. While I personally think this is a wonderful feature, Microsoft allows users to unsubscribe from the emails. This got me thinking, is there a way to see who has unsubscribed from the auto-news digest emails and may therefore be missing key announcements?

It turns out there is no beautiful report that can be easily generated in the admin center. However, our faithful friend PowerShell is able to lend us a hand here. Specifically, the wonderful PnP community have created a cmdlet that does exactly what we need, albeit for each individual user.

Therefore, I have wrapped this up into a cheeky little loop to generate a list of users and who are and aren’t currently subscribed to the digest emails. If you don’t want to bother reading how it works, you can find a download link at the bottom of this page.

Behind the Scenes

When a user unsubscribes from the digest emails, this is recorded in a hidden list in the user’s OneDrive site as we can see here.

Hidden list showing in PowerShell

If we go and have a look in this list, we can see an item has been added to disable the auto-news digest emails, as with other types of SharePoint notifications.

Hidden list being viewed in bro

Important Note!
The PnP cmdlet we are using in the below script is looking in this list to check if the user has unsubscribed. In order for it to do this, we need access to the users OneDrive site to be able to query this list.

I personally manage this by having a Security Group configured as Secondary Admin on all OneDrive Sites, and just drop my account in there when I need to run a script such as this one. I will write a separate post on how to do this.

The Script

Here’s how it works. Firstly we connect to PnP Online. To run this script, you need to connect to the SharePoint Admin Centre URL. Once connected, we pull a list of active users who are not guests and initialise an array to store the output.

Connect-PnPOnline -Url "https://[TENANTNAME]-admin.sharepoint.com"
$users = Get-PnPAzureADUser -Filter "accountEnabled eq true and UserType eq 'Member'" -EndIndex $null
$subscriptionStatus = @()

Now we have a list of users, we can start looping through and checking whether they are subscribed. Once the loop is initialised, we call the Get-PnPSubscribeSharePointNewsDigest cmdlet for each user and do something with the response. There are a few reasons that cause this to error, so we have to wrap this in a try-catch and act accordingly.

If the user has never unsubscribed from the digest emails, the list will not exist and therefore throws an error. We treat these users as “Subscribed”. Additionally, if the user does not have a OneDrive site, either because they are not licensed or they have never logged in, the cmdlet returns an error. In this scenario, I just output an “n/a” but you can change this if you want.

$users | % {

    try {
        $userStatus = Get-PnPSubscribeSharePointNewsDigest -Account $_.UserPrincipalName -ErrorAction Stop
        $isSubscribed = $userStatus.Enabled
    } 
    catch {
        if ($Error[0].Exception.Message -like "*(401)*") {
            $isSubscribed = "n/a"
        }
        if ($Error[0].Exception.Message -like "*(403)*") {
            $isSubscribed = "Access Denied"
        }
        if ($Error[0].Exception.Message -like "*Sequence contains no matching element*") {
            $isSubscribed = $true
        }
    }

Finally, we consume the output into something useful. I do this by building a PSObject and adding that to an array. I then also add up the totals and output this to the console for interest.

    $userSubscriptionStatus = New-Object PSObject
    $userSubscriptionStatus | Add-Member NoteProperty UPN $_.UserPrincipalName
    $userSubscriptionStatus | Add-Member NoteProperty IsSubscribed $isSubscribed
    $subscriptionStatus += $userSubscriptionStatus

    $subscribedCount = ($subscriptionStatus | select isSubscribed | ? isSubscribed -eq $true).Count
    $unubscribedCount = ($subscriptionStatus | select isSubscribed | ? isSubscribed -eq $false).Count

    Write-Host "Subscribed: $subscribedCount"
    Write-Host "Unsubscribed: $unubscribedCount"

}

There you have it, you can now see which of your users have unsubscribed from auto-news digest emails. It’s not the most elegant script ever, but it does the job. When I share a script I deliberately try and keep things extremely simple to allow it to be modified to suit your needs without too much effort.

Download

To download the full script and any future updates I may make, you can find it on GitHub here.

Credit where its due
Featured Image by talha khalil from Pixabay

Copyright © 2020 - Martin Day