Forum Discussion
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 find commands to show presence.
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
- kyazaferrIron 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 MicrosoftTeamsConnect to Microsoft Teams You need to authenticate to Microsoft Teams using your tenant credentials:
$credential = Get-Credential
Connect-MicrosoftTeams -Credential $credentialRetrieve 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).
- kyazaferrIron Contributor
# Ensure Teams PowerShell Module is installed
Install-Module -Name MicrosoftTeams -Force -AllowClobber
Import-Module MicrosoftTeams# Connect to Microsoft Teams
$credential = Get-Credential
Connect-MicrosoftTeams -Credential $credential# Function to get presence status for all users in the tenant
Function Get-TeamsPresence {
$users = Get-TeamUserPresence
$results = @()foreach ($user in $users) {
# Output user presence status and the time they were last active
$userStatus = New-Object PSObject -property @{
UserName = $user.User
Presence = $user.Presence
LastActivityTime = $user.LastActivityTime
}
$results += $userStatus
}
return $results
}# Function to report presence
Function Report-UserPresence {
$results = Get-TeamsPresence
$currentTime = Get-Dateforeach ($user in $results) {
$timeDiff = $currentTime - $user.LastActivityTime
if ($timeDiff.TotalMinutes -gt 60) { # If more than 60 minutes idle
Write-Host "User $($user.UserName) has been idle for $([math]::Round($timeDiff.TotalMinutes, 2)) minutes."
# Action to reset presence could be added here with Microsoft Graph API if available
# Example: Update presence using Microsoft Graph API (if such an endpoint is available)
# ResetTeamsPresence($user.UserName)
} else {
Write-Host "$($user.UserName) - Current Status: $($user.Presence) - Last Active: $($user.LastActivityTime)"
}
}
}# Call function to report status and reset after time
Report-UserPresence# To automate resetting the status after a specific time
# You would need to use Microsoft Graph API (Presence API) or set up a flow in Power Automate if needed - Bridget_TBrass Contributor
Thank you for the replies. However, this doesnt get to the bit I require. I am looking to find the "Reset Status After" field, as I showed in the print screen above. I cant seem to find how to access that data. I'm sure its hidden in the near vacinity of where you show, but I just cant extract it.
- LainRobertsonSilver Contributor
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- Bridget_TBrass Contributor
Thanks for the update.