0

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.

Steve Norwood
  • 363
  • 5
  • 19
  • You can use the Graph API to create a channel and teams. Number of channels per team-200 (includes deleted channels) https://learn.microsoft.com/en-us/graph/api/channel-post?view=graph-rest-1.0&tabs=http https://learn.microsoft.com/en-us/microsoftteams/limits-specifications-teams – Sayali-MSFT Apr 27 '22 at 06:18
  • I am trying to avoid having to create an application to authenticate against using the Graph API, which is why I went down the PowerShell route. From a brief bit of research (https://stackoverflow.com/questions/56829758/make-microsoft-graph-api-calls-without-registering-the-app), it doesn't look like I can authenticate to the Graph API without registering an app. – Steve Norwood Apr 27 '22 at 07:14

0 Answers0