As we are mainly responsible for general question of Microsoft Teams, script is not in our service scope. The following processes just provide ideas and methods. Then, you should combine them together.
First of all, you should create a UserInfo.csv file which contains all the members and owners corresponding to teams’ GroupId. Save this file in c:\Temp\UserInfo.csv.
The following image is an example:
Secondly, Connect to Microsoft Teams module:
$User = ******@xxxx.onmicrosoft.com
$PassWord = ConvertTo-SecureString -String "**YourPassword**" -AsPlainText -Force
$UserCredential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PassWord
import-module microsoftteams
Connect-MicrosoftTeams -Credential $UserCredential -AccountId $User
At last, using Add-TeamsUser command to add owners and members one by one to teams. A conditional statement is necessary here. The following code snippet is for reference:
$users = import-csv c:\Temp\UserInfo.csv
Foreach($user in $users)
{
Add-TeamUser -GroupId $user.GroupID -User $user.UserID -Role $user.Role
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.