Forum Discussion
Bridget_T
Nov 12, 2024Brass Contributor
script to use PowerShell to Report Teams Status, Presence and Reset After Time
I would like to create a powershell script to run against my tenant to report where people have got a Reset Status After time coded in Teams Any suggestions - greatfully received. I can only fin...
- Nov 18, 2024
Hi Bridget_T ,
This is more of a Teams question than a PowerShell question, so you might want to also ask this in a Teams forum.
Having had a read of the v1 and beta Graph presence endpoint, I does not seem that what you are wanting to do is possible. This is for two reasons:
- Teams can have multiple clients connected to it, where each client is responsible for managing its own polling and setting of the per session status;
- The "set presence" endpoint does not support a value for "reset status", adding weight to the above point that this is not managed service-side, but rather within each client's session.
Because the "reset" behaviour is being actioned by each client, that means there is nothing to query from the service itself, which is reflected in the "get presence" endpoint where the JSON response contains no such data.
Put another way: Setting a reset value within the Teams desktop client means its then that desktop client's responsibility to perform the reset behaviour. If you concurrently ran Teams mobile and Teams web, they would be unaware of the reset value from Teams desktop. Similarly, there is nothing to query from the Teams service since it's the Teams desktop client holding these settings and actioning the behaviour.
Reference articles:
- presence: setPresence - Microsoft Graph beta | Microsoft Learn
- Get presence - Microsoft Graph beta | Microsoft Learn
As I mentioned earlier though, it would be worth your while asking in a Teams forum, where you might expect to find more Teams-proficient people. Another option might be to ask in a Power Platform forum, as Power Platform solutions are a prolific consumer of Graph endpoints.
In not being a Teams afficionado, and going off the Graph endpoint documentation, I can't see a way to achieve what you're hoping to achieve.
Cheers,
Lain
kyazaferr
Nov 13, 2024Steel Contributor
Install Teams PowerShell Module First, install and import the Teams PowerShell module:
Install-Module -Name PowerShellGet -Force -AllowClobber
Install-Module -Name MicrosoftTeams
Import-Module MicrosoftTeams
Connect to Microsoft Teams You need to authenticate to Microsoft Teams using your tenant credentials:
$credential = Get-Credential
Connect-MicrosoftTeams -Credential $credential
Retrieve Users' Presence Status To retrieve users' presence status, we can use Get-TeamUserPresence (from the Teams module). Here’s a basic command:
$users = Get-TeamUserPresence
foreach ($user in $users) {
Write-Host "$($user.User) - $($user.Presence)"
}
Report and Reset Teams Presence Unfortunately, there is no direct command to "reset" presence status from the Teams PowerShell module. You can manually set the presence by using Teams client-side features or Microsoft Graph API.
For demonstration purposes, we can set a simple logic to report the user presence status for users who have been idle for a period, then take an action based on that (e.g., resetting status by updating the Presence).