March 5, 2020

Add list of users to a Microsoft Teams Team e.g. from Outlook, Excel using the PowerTools

It is right now quite cumbersome to add a list of users you have the email of to a Microsoft Teams Team in a bulk way. The client UI does not offer this. (You need to add users one by one).
The currently most practical way is using a PowerShell script but still it might be some work to get it running. (Edit: see alternative using Power Automate)
I present here a solution implemented in AutoHotkey that can seamlessly add a list of users you already have in Outlook or Excel or a list of Emails in your clipboard to a Team.
It is implemented in the People Connector PowerTool.

Current Pain


Teams PowerShell setup

See separate post here.

People Connector Feature Highlight


The feature works from any selection containing email addresses e.g. also from an Outlook item.

From an Outlook Email or meeting or Excel file or wherever you can copy the emails to your clipboard, select the list of colleagues you want to add to the target team example in the To: field, select all with Ctrl+A. 
Open the PeopleConnector menu (Double shift) or from the TeamsShortcuts menu (Click on the Tool System Tray Icon) and select the menu entry "Add users to Team". 
Copy the Team Link and paste it in the prompted input box. That's it. (Prerequisite: PowerShell for Teams was setup - see separate post)

The tool will take care for you to create and run the PowerShell script behind the scenes.

Implementation notes

Add Users from Email List to a Team with PowerShell via AutoHotkey is done in ahk/Lib/Teams.ahk ->Teams_Emails2Users as shown in extract below

Teams_Emails2Users(EmailList,TeamLink:=""){
; Syntax: 
;     Emails2TeamMembers(EmailList,TeamLink*)
; EmailList: String of email adressees separated with a ;
; TeamLink: (String) optional. If not passed, user will be asked via inputbox

If !Teams_PowerShellCheck()
    return

If (TeamLink=="") {
    InputBox, TeamLink , Team Link, Enter Team Link:,,640,125 
    if ErrorLevel
        return
}
sPat = \?groupId=(.*)&tenantId=(.*)
If !(RegExMatch(TeamLink,sPat,sId)) {
    MsgBox 0x10, Error, Provided Url does not match a Team Link!
    return
}
sGroupId := sId1
sTenantId := sId2

; Create csv file with list of emails
CsvFile = %A_Temp%\email_list.csv
If FileExist(CsvFile)
    FileDelete, %CsvFile%
sText := StrReplace(EmailList,";","`n")
FileAppend, %sText%,%CsvFile% 
; Create .ps1 file
PsFile = %A_Temp%\Teams_AddUsers.ps1
; Fill the file with commands
If FileExist(PsFile)
    FileDelete, %PsFile%

Domain := People_GetDomain()
If (Domain ="") {
    MsgBox 0x10, Teams Shortcuts: Error, No Domain defined!
    return
}
OfficeUid := People_GetMyOUid()

sText = Connect-MicrosoftTeams -TenantId %sTenantId% -AccountId %OfficeUid%@%Domain%
sText = %sText%`nImport-Csv -header email -Path "%CsvFile%" | foreach{Add-TeamUser -GroupId "%sGroupId%" -user $_.email}
FileAppend, %sText%,%PsFile%

; Run it
RunWait, PowerShell.exe -NoExit -ExecutionPolicy Bypass -Command %PsFile% ;,, Hide
;RunWait, PowerShell.exe -ExecutionPolicy Bypass -Command %PsFile% ,, Hide
}

See also

Uservoice:18240376-improve-add-members-to-team

Uservoice: 38483002-bulk-add-team-members-via-csv-file

Teams powershell setup

Microsoft Teams: Export Team Members to Excel | Thierry Dalon's Blog

No comments:

Post a Comment