Forum Discussion
markgort
Feb 26, 2020Copper Contributor
When creating multiple channels within a newly created team (Folders are not created in SharePoint)
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 Pow...
TrynaDoStuff
Nov 10, 2022Copper Contributor
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.
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.
Tedley63
Jun 20, 2023Copper Contributor
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();