Home > Back-end >  Microsoft Teams Powershell. How to get the email address of the person logged on
Microsoft Teams Powershell. How to get the email address of the person logged on

Time:05-11

I'm sure this is easy, but it's doing my head in. I'm very new to Powershell.

Accessing the Teams powershell is no problem.

Connect-MicrosoftTeams

This brings up a dialog, and asks me to select an account, and all I need to do is to click on mine.

I get a display telling me my "account" - which is my email address.

From there I want to establish a number of things that apply to "me".

I have a piece of code that will allow me to get a list of those things either to the screen or to a .csv file by electing 1 or 2 at a prompt.

In order to this script to work it relies on lines like this

*

$AllTeams = Get-Team -User "my.emailaddress@somedomain"
Foreach ($Team in $AllTeams)

What I need is to be able to replace my.emailaddress, with the email address taken from the "account" mentioned above. (i.e My email address that the system has used to log me in)

That is, the teams powershell knows my email address, I can see it on the screen. How can I capture this to a variable, and then feed that in later on?

This would enable other people to run the same script without having to amend it every time, and get the similar report, but based on themselves. Is there something like

current account or"me" or currentuser smtp?

Get credential is no use because I am already past security with a single mouse click. Similarly all the other commands and functions I've seen don't tell me anything about the current user. Thanks

CodePudding user response:

The easiest way is to save the Teams connection information from Connect-MicrosoftTeams into a variable. The email used to connect is stored in the Account.id field:

$TeamsInfo = Connect-MicrosoftTeams
$TeamsInfo.Account.id
  • Related