Get the link of a Microsoft Teams team with PowerShell

So let’s say you have already made a team in Microsoft Teams. All members of the team has already got an invitation link.

A while later someone asks for the link to the team. How can you get it? – PowerShell to the rescue!

To use the PowerShell script here you need to install the “Microsoft Teams module for PowerShell” elevated PowerShell window, running the command:Install-Module -Name MicrosoftTeams.

To use the script just add the team display name to the variable $teamDisplayName = "", or the team Group ID to the variable $groupID = "" and run the script.

#Enter team display name or group ID
$teamDisplayName = ""
$groupID = ""

#Team link template
$teamLinkTemplate = "https://teams.microsoft.com/l/team/<ThreadId>/conversations?groupId=<GroupId>&tenantId=<TenantId>"

#Connect to Microsoft Teams
$connectTeams = Connect-MicrosoftTeams

#Retrieve the team via display name or group ID
$team = Get-Team | Where-Object {$_.DisplayName -eq $teamDisplayName -or $_GroupId -eq $groupID} | Select-Object -First 1

#Retrieve team channel General (can be replaced by another Channel if needed)
$channel = Get-TeamChannel -GroupId $team.GroupId | Where-Object {$_.DisplayName -eq "General"} | Select-Object -First 1

#Construct the team link
$teamLink = $teamLinkTemplate.Replace("<ThreadId>",$channel.Id).Replace("<GroupId>",$team.GroupId).Replace("<TenantId>",$connectTeams.TenantId)
$teamLink

If a user has not received an invitation link, but they are already a member of the team, you can just send them this link. It is also a great way to refer to a team without actually being a member of the team, like most admins…


Sources

Thanks to @zaab_it for the original post: https://medium.com/@zaab_it/microsoft-teams-get-link-to-team-8dd9d5b5a65d

Leave a Reply

Your email address will not be published. Required fields are marked *