Clockless Start your free month

Can I log Teams status myself with Graph or PowerShell?

You can. Microsoft Graph returns each person's current Teams status, and a script that asks every few minutes and saves the answers gives you a status log. What it takes: an app registration with the Presence.Read.All permission and an administrator's consent, something that runs the script every few minutes, somewhere to keep the results, and the work of turning thousands of rows into something an owner will read. This page sets out each part, with a short PowerShell sketch, so you can judge whether to build it or buy it.

What does Microsoft Graph give you?

The current status, not a history. A presence record has an availability (such as Available, Busy or Away) and an activity (such as InACall or InAMeeting) (Microsoft Graph: presence resource). Microsoft's list of properties has no start time and no "last seen" field (see What does "Last seen" mean in Microsoft Teams?).

To read many people at once, Graph has getPresencesByUserId. Microsoft's page says (Microsoft Graph: getPresencesByUserId):

  • It needs the Presence.Read.All permission, as a delegated permission (a signed-in user) or an application permission (a script running on its own).
  • A "maximum of 650 user IDs are supported per API request".
  • The "maximum request rate of this API is 1500 API requests in a 30 second period, per application per tenant".

For a small business, one request every few minutes covers everyone with room to spare.

Can't I get notified when someone's status changes instead?

Not from a script running on its own. Graph can send change notifications for presence, but Microsoft's page lists the application permission as "Not supported": only a signed-in user's delegated permission works. Microsoft sets "a maximum expiration time of an hour" for each subscription, so it has to be renewed before it runs out (Microsoft Graph: change notifications for presence).

So an unattended log usually asks on a schedule (polling) rather than waiting to be told.

What does a minimal PowerShell version look like?

Here's a sketch using the Microsoft Graph PowerShell modules. It signs in as an app with a certificate, reads the staff list, asks for everyone's status in batches of 650, and adds the answers to a CSV file. It's a starting point to test in your own tenant, not finished software.

# Needs: Install-Module Microsoft.Graph.Users, Microsoft.Graph.CloudCommunications
# App registration with application permissions Presence.Read.All and User.Read.All, admin consented
Connect-MgGraph -ClientId $appId -TenantId $tenantId -CertificateThumbprint $thumbprint

$ids = @((Get-MgUser -All -Property Id).Id)
$now = (Get-Date).ToUniversalTime().ToString("o")

for ($i = 0; $i -lt $ids.Count; $i += 650) {
    $batch = @($ids[$i..([Math]::Min($i + 649, $ids.Count - 1))])
    Get-MgCommunicationPresenceByUserId -BodyParameter @{ ids = $batch } |
        Select-Object @{ n = 'TimeUtc'; e = { $now } }, Id, Availability, Activity |
        Export-Csv -Path C:\StatusLog\presence-log.csv -Append -NoTypeInformation
}

Get-MgCommunicationPresenceByUserId is the PowerShell form of getPresencesByUserId; Microsoft's own example on that page uses it with -BodyParameter. Run it every 5 minutes with Task Scheduler and you have a raw status log. (Azure Automation works too, but doesn't keep local files between runs, so save the rows to storage such as an Azure storage account.) Get-MgUser -All also returns guests and disabled accounts; filter those out if you don't want them logged.

What's left after the script works?

Most of the work. A log of rows isn't yet something an owner can read. You'd still need to:

  • Keep it running. A computer that sleeps or restarts leaves gaps. Certificates and secrets expire and need replacing.
  • Store it safely. A status log is a record about named staff. Decide who can open the file, and how long you keep it.
  • Turn samples into a day. Work out each person's start and finish from a status every 5 minutes, ignoring a single Available reading at 11 pm.
  • Know each person's working pattern. Part-time days, hours and weekly targets.
  • Allow for holidays and time zones. Public holidays differ by state and country, and staff in other places start on their own clock (see Staff in more than one state).
  • Deal with people joining and leaving, and match each ID to a person's name.
  • Write the report and send it. Weekly, monthly, by email, to the right people only.
  • Tell staff first. Recording status over time is something staff should hear about from you, in writing, before it starts.

When is it worth doing yourself?

Probably worth it if: you have an IT person with time to build and look after it, you want the raw data in your own systems (for example Power BI), or you need something no product offers.

Probably not if: what you want is a short report each Monday, and nobody has time to keep a script alive.

That second case is what we built Clockless for. It does the collecting, each person's public holidays and time zone, the reports and the emailing, for A$4 a person a month in Australia, or US$3 in the US, excluding tax. It reads Teams status, the staff list and usage counts, and it can't read email, chats or files. We make it, so weigh that. The script above is a fair way to start if you'd rather own the whole thing.

Related guides


To see how a week of Teams status reads in a report, open the sample report (made-up people and numbers). If it would help your business, start your free month (first time? follow the set-up steps).

Clockless turns Microsoft Teams status into weekly working hours reports. See how it works.