Forum Discussion

D_Lewis79's avatar
D_Lewis79
Copper Contributor
Jun 17, 2021

Foreach loop output file

Hi all, 

 

Some expert help please... I am really happy with how a foreach loop is working as I would expect it but I can't find a solution to export the results to a text file. The code is below: 

 

# Get all the teams from tenant
$teamColl=Get-Team

# Loop through the teams
foreach($team in $teamColl)
{
Write-Host -ForegroundColor Magenta "Getting all the channels from Team: " $team.DisplayName

# Get the channels for Team
$channelColl= Get-TeamChannel -GroupId $team.GroupId #-MembershipType Private

# Get the team owners
$ownerColl= Get-TeamUser -GroupId $team.GroupId -Role Owner

#Loop through the Teams
foreach($channel in $channelColl)
{
Write-Host -ForegroundColor Yellow "ID: " $channel.Id " Display Name: " $channel.DisplayName " Desc: " $channel.Description " Membership Type: " $channel.MembershipType

#Loop through the owners
foreach($owner in $ownerColl)
{
Write-Host -ForegroundColor Red "User ID: " $owner.UserId " User: " $owner.User " Name: " $owner.Name
}
}
}

 

Please give me any assistance. Thank you. 

Resources