Forum Discussion

lkimble711's avatar
lkimble711
Copper Contributor
Aug 30, 2023

Powershell Script to see if someone is in an active Teams call/meeting

Hello all,

  Is there a way to tell via aPowerShell script if someone is currently in a Teams call?

2 Replies

  • lkimble711 

    You can try this graph API query, in PowerShell command execution

    enable "Presence.ReadALL" graph API permission on your APP.

     

    $ClientID = "your client ID" #App ID

    $ClientSecret = "your secret"

    $TenatDomainName = "yourdomain.com"

    $tenantId = "Tenant ID" 

    $Body = @{   

    Grant_Type    = "client_credentials"

    Scope         = "https://graph.microsoft.com/.default"

    client_Id     = $ClientID

    Client_Secret = $ClientSecret

    }

     

    $ConnectGraph = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" `

    -Method POST -Body $Body

    $token = $ConnectGraph.access_token

     

    ########################################################################

     

    # Get all users Presence Status.

     

    Write-Verbose -Verbose -Message "Getting all users Presence Status...."

     

    $UsersGpUri = 'https://graph.microsoft.com/v1.0/users?$select=id,displayName'

    $Graphresult = (Invoke-RestMethod -Headers @{Authorization = "Bearer $($token)"} -Uri $UsersGpUri -Method Get)

    $Gpusers = @()

    $Gpusers += $Graphresult.value

     

    $Pages = $Graphresult.'@odata.nextLink'

    while($null -ne $Pages) {

    Write-Warning "Checking Next page"

    $Addtional = Invoke-RestMethod -Headers @{Authorization = "Bearer $($Token)mailto:%22%20%7d%20-Uri%20$Pages%20-Method%20Get%0dif%20($Pages)%7b%0d$Pages%20=%20$Addtional.%22@odata.nextLink

    mailto:%22%20%7d%20-Uri%20$Pages%20-Method%20Get%0dif%20($Pages)%7b%0d$Pages%20=%20$Addtional.%22@odata.nextLink

    mailto:%22%20%7d%20-Uri%20$Pages%20-Method%20Get%0dif%20($Pages)%7b%0d$Pages%20=%20$Addtional.%22@odata.nextLink"

    }

    $Gpusers += $Addtional.value

    }

    $users = $Gpusers

    foreach ($user in $users)

    {

        $UserID = $user.id   

        $userName = $user.displayName   

            $UserPresenceUri = "https://graph.microsoft.com/v1.0/users/$UserID/presence"

            $GraphPreresult = (Invoke-RestMethod -Headers @{Authorization = "Bearer $($token)"} -Uri $UserPresenceUri -Method Get)

            $userPresence = $GraphPreresult.availability

            $UsersPre = @()

            #$GpPreusers += $GraphPreresult.value

            $UsersPre +=[PSCustomObject]@{

                    userName = $userName

                    Presence = $userPresence

                    }

                    $UsersPre

        }

Resources