When creating multiple channels within a newly created team (Folders are not created in SharePoint)

Copper Contributor

I'm working on some automation with the Microsoft Teams PowerShell module. But after creating a new Microsoft Team and directly create some channels the folders are not created. As attachment the PowerShell script and .csv (import file) i use to automate this proces.

 

As attachment i upload the scripts i use in this scenario. I also raised a support ticket within the admin center. But they don't deliver support on PowerShell scripts and re-routed me to the Premium support. 

6 Replies

Since Teams provisions multiple resources across different workloads, the process can take a while (even up to 24h) to complete. If you want to provision folders/files immediately, use the corresponding SPO tools (CSOM or the Graph API endpoints).

@Vasil Michev you're right that provision of teams sometimes can take up to 24 hours, but after running the command "New-TeamChannel" a folder should be created directly in SharePoint Online. In this case i created a script (see attachment) with and iteration to create multiple channels with different names. Folders are not created in SharePoint Online, if i run this command directly in PowerShell the specific folder is created directly. 

 

It's possible to reproduce this issue with the following two commands (first wait until the first command is finished) and then run the second one

$team = New-Team -DisplayName "TestTechCommunity"

New-TeamChannel -GroupId $team.groupId -Displayname "test"

 

In this scenario the channel is visible in teams but if you look in SharePoint, no folder is created. 

I'm having the same issue, Teams public channels are visible in Teams, but the associated folder(s) on the SharePoint document library are not created. Using the following script from Teams Module
New-TeamChannel -GroupId $Team.GroupId -DisplayName "Test"

The folder associated to the public Teams channel is created in SharePoint only after I click on the Teams Channel -> Files Tab.
I found a solution to this, but you will need to create an app registration and connect via the Teams API, and run this for each channel after it is created in the script:

https://learn.microsoft.com/en-us/graph/api/channel-post?view=graph-rest-1.0&tabs=http

$channelCreated = Invoke-RestMethod -Uri $CreateChannelURL -Method Post -body $CreateChannelBody -Headers $M365headerParams_MSG -ContentType Application/JSON
write-host "Channel created:" $channelCreated.displayName -NoNewline -ForegroundColor Cyan

#We need to send another call in order to initialise the folder structure in SPO
$initialiseFolderURL = "https://graph.microsoft.com/v1.0/teams/$TeamID/channels/"+$channelcreated.id+"/filesfolder"
$initialisefolder = $null
$initialisefolder = Invoke-RestMethod -Uri $initialiseFolderURL -Method Get -Headers $M365headerParams_MSG
if ($initialisefolder) {write-host "Channel initialised in SPO" -ForegroundColor Yellow}

That last line "initialises" the folder within the SharePoint Site Document library.

@TrynaDoStuff   Perfect!  This should have better visibility as many people are having the same issue when automating deployments!

Note, if you're using the client sdk from c# it can be done in similar fashion (non-async):

GraphClient.Teams[Team.Id].Channels[Channel.Id].FilesFolder.Request().GetAsync().GetAwaiter().GetResult();

 

@TrynaDoStuff thanks for sharing this information.

For others looking for implementing this solution, you could achieve this in Power Automate / Logic Apps as follows:

Picture1.png

Indeed I configure authentication based on an app registration as you suggested.