I'm trying to create a set of test data for Teams, where I need a large amount of Teams and channels.
I have been roughly following this guide, but without the XML document. Instead, I have for loops to create a large amount of teams/channels. The script mostly works, but I have run into two issues.
Firstly, I am receiving an error when adding over ~60 channels to a team. However, the error that I am being given is very vague and I'm not sure if this is a bug with the Teams PowerShell module. This is the code I have for creating the channels:
for ($j = 0; $j -lt $channelCount; $j++) {
try {
New-TeamChannel -GroupId $groupId -DisplayName "Test Channel $($j)" | Out-Null
Write-Host "Successfully created channel: Test Channel $($j)"
}
catch {
Write-Host "Could not add channel"
$e = $_.Exception
$msg = $e.Message
while ($e.InnerException) {
$e = $e.InnerException
$msg += "`n" + $e.Message
}
Write-Host -Foreground Red $msg
}
}
I got the error handling code from here, and the error is not very helpful:
Could not add channel
One or more errors occurred.
Cannot access a disposed object.
Object name: 'System.Net.Http.StringContent'.
Is there anything that I'm doing wrong here?
The other issue I've got is that the whole process is very slow. I'm not too experienced in using Powershell, but is there a better way to speed it up? I'm not sure if I could run some of the code in parallel, but I don't know what the Graph API limits would be, but happy to try it if anyone could give me some pointers.