I have a script with 2 Foreach loops. The first works with no issues, but when I add the second it adds every user value in the column to each Team. I can't see where/why its going wrong and I'm hoping someone can point it out to me.
#Read team users from CSV file
$teams = import-csv "File_Path"
#Iterate team user details one by one
Foreach($team in $teams)
{
$DisplayName = $teams.'TeamDesc'
$Description = $teams.'Code'
$Visibility = $teams.'Visibility'
$Owner = $teams.’UserPrincipleName’
$group = New-Team -DisplayName $team.TeamDesc -Owner $team.UserPrincipleName -Description $team.Code -Visibility $team.Visibility
Foreach($team in $teams)
{
$Group = (Get-Team -DisplayName $team.'TeamDesc').GroupId
$User = $teams.'DepartmentChair'
Add-TeamUser -GroupId $group.GroupId -User $team.'DepartmentChair' -Role ‘Owner’
}
}