Saturday, August 26, 2023

How to get Teams User id using Microsoft Teams Module


We can get Teams user id  using MicrosoftTeams powershell module

 1.Install  MicrosoftTeams Powershell module

```sh
# Install  Microsoft Team  powershell module

Get-module *teams* 

Install-Module -Name MicrosoftTeams

Update-Module MicrosoftT

```

 2.Connect to Team Tenant 

```sh
#  Connect to Team Tenant 

Connect-MicrosoftTeams 

# It will prompt for AAD Login else # or  you can specify credentials through script
$credential = Get-Credential
Connect-MicrosoftTeams -Credential $credential

```
` Note :Unfortunately, it is not possible to connect to Microsoft Teams using the Connect-MicrosoftTeams cmdlet with **MFA enabled without using an interactive 	  login**. If you want to automate the process of connecting to Microsoft Teams, you may need to use a service account that does not have MFA enabled or use a different method of authentication, such as using a certificate or an application ID


 3.Get group id for Your teams group
```sh
$groupid=$(Get-Team -DisplayName 'Your-Teams-Group' |select GroupId)
```


 4.Get teams UserId

```sh

$users=$(Get-TeamUser   -GroupId $groupid  )
$UserID=$(Get-TeamUser   -GroupId $groupid  | where name -EQ "Your-User-Name").UserID

```


Complete Script 

```sh

Get-module *teams* 
Install-Module -Name MicrosoftTeams
Update-Module MicrosoftTeams 
Connect-MicrosoftTeams
$groupid=$(Get-Team -DisplayName 'Notifications' |select GroupId).groupid

$UserID=$(Get-TeamUser   -GroupId $groupid  | where name -eq "Raj").UserI
```

No comments:

Post a Comment