When using MS Teams, EXO and Azure via PS I want to script check connection/session status before the script continues.
Connecting to these services is fine e.g. Connect-MicrosoftTeams
Then connection info is displayed e.g.
Account Environment Tenant TenantId
firstname.lastname@example.org AzureCloud xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
But, how get this info otherwise? As using Get-PSSession shows nothing almost everytime .... by that I mean sometimes I can see a session almost every other time $null result. When there is a PSsession actually showing it usually has a status of 'broken' and yet can successfully run Teams cmdlets without issue.
So how to confirm AzureCloud services (MS Teams, EXO, Azure/AD) connection/session status?
I've tried searching this and not found any results for verifying session status. No mention of it in MS Docs for the Connect-* cmdlets or in the MS Docs Get-PSSession
My workaround has been to prompt to connect and disconnect MS Teams at start and end of script. It makes sense to have the script be able to check connection status. As I would do when scripting PS sessions to on-prem Exchange, AD, etc. previously.