As mentioned in the title, I am trying to add multiple users to multiple Teams through Powershell using a .csv file. The problem I am having is that my .csv includes only the Team name, and not the GroupID. I need to be able to reference the team name and look up the corresponding GroupID, and then have that ID used in the add user phase. Is this even possible?
Here is what I have worked up so far:
#Read team users from CSV file
$TeamUsers = Import-CSV "File_Path"
$i = 0;
$TotalRows = $TeamUsers.Count
#Iterate team user details one by one
Foreach($TeamUser in $TeamUsers)
{
$TeamName = $TeamUser.'TeamName'
$GroupId = (Get-Team -DisplayName 'TeamDesc').GroupId
$UserId = $TeamUser.'UserPrincipalName'
$Role = $TeamUser.'Role'
$i++;
Write-Progress -activity "Processing $TeamName - $UserId - $Role" -status "$i out of $TotalRows completed"
Try
{
#Add user to the team
Add-TeamUser -GroupId $GroupId -User $UserId -Role $Role
}
catch
{
Write-Host "Error occurred for $TeamName - $UserId" -f Yellow
Write-Host $_ -f Red
}
}
The headers of my .csv include "UserPrincipleName", "TeamDesc", and "Role". The Team name is stored in the "TeamDesc" column.