Setting Do Not Disturb via Graph API

I know I can set my status as Do Not Disturb via Teams or by having Viva book Focus time slots for me automatically.

The latter is good, but I have no control over what times it books. The former… I do this thing nowadays of not opening Teams for a stretch of time so I get no notifications (setting it as Offline/ Busy/ Do Not Disturb doesn’t help as I still take a peek when the badge icon shows a number; and sometimes I click it anyways and that’s not helpful either).

So what I really want is a way of setting Do Not Disturb manually, without opening Teams.

Graph to the rescue!

Am sure there’s other ways of doing this, but this is what I did.

First, I created an App Registration and granted it the “Delegated” Presence.Read and Presence.ReadWrite permissions. Did the Admin Consent to these. All you need is the Application Administrator role for this; these are Delegated Permissions after all and don’t do any damage.

I enabled public client flows (not strictly needed, but it’s required for the way I will be using this).

I took note of its App Id and the Tenant Id. Also my user Id (the GUID).

Then I do the following in PowerShell:

And that’s it, I am set as DND for the next 1 hour. Change “PT1H” to “PT2H” for 2 hours, and so on. The valid duration range is 5-240 minutes (PT5M to PT4H)

I use Device Authentication as a personal preference, but I could have skipped that switch too and Graph will open up a login page in the default browser.

Nice, huh!

Update: Came across this post on setting the Teams status message too. Must look into it. Very nifty! (And from that this one, and this one). So – you can use the HTTP request to SharePoint connector to do some interesting “authenticated” stuff. Looks like these two posts were written before the Graph API method above; the latter is still limited in that I can’t set a status message. I am inclined towards the Power Automate way though, it’s very cool! :)

Further update: I don’t think the methods in the above post work any more..