Locally detecting a user’s sign in to Microsoft Teams

A customer wanted to see when/if users were doing their first sign in to MS Teams (on new devices), and if this was against their tenant. Mostly untested but for the world since I couldn’t google it:

function checkTeams(){
    $teamsLogPath = Join-Path $($env:LOCALAPPDATA) "packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams\ecs_request_param.json"
    if((Test-Path $teamsLogPath)){
        $state = Get-Content $teamsLogPath | ConvertFrom-JSON
        if($state -and $state.tenantId -eq "YOUR TENANT GUID"){
            return $true
        }else{
            return $false
        }
    }else{
        return $false
    }    
}

Get-CsTeamsMeetingPolicy: Invalid credential Provide valid credential.

For those googling, above error happened for us when trying to use application-based authentication for the MS Teams PowerShell commandlets.

We followed the instructions but kept getting Invalid credential Provide valid credential whenever calling a cmdlet, while the connect-microsoftteams command worked fine with the -accesstokens param.

Turns out, when you assign application level permissions to your service principal on top of the delegated permissions, the SPN is not authorized for all subsequent cmdlet calls :O