I want to look up which users populate which teams and export the info to a csv. I am able to get the user info, but I want to preserve info for which Team they occupy. So far, I am only able to export the last entry from my source csv to my exported data.
#Import Teams list from importFile.csv
$Teams = Import-CSV "importFile.csv"
#Capture Team names for later export
$Teams | Select-Object 'TeamDesc' | ForEach-Object {$teamName = $_.TeamDesc}
#Iterate through list
ForEach($Team in $Teams)
{
#Get Team GroupID from TeamDesc column
$GroupId = (Get-Team -DisplayName $Team.'TeamDesc').GroupId
#Get Team user info, select values, and export to destinationFile.csv
Get-TeamUser -GroupId $GroupId -Role 'Member' | Select-Object 'User','Name',$teamName | Export-CSV -NoTypeInformation "exportFile.csv" -Append
}
Is there a way to apply the "TeamDesc" info to each of the users it gathers from the respective Teams?