The MailFolders Endpoint
"https://graph.microsoft.com/v1.0/users/$mailbox/mailFolders"
Lets you list and create a folder in the MailboxFolderRoot so it equivalent to
/MailFolders('MsgFolderRoot')/childfolders
There is no way of doing a deep traversal with the Graph at the moment (meaning you traverse every layer of childfolders) you can do one layer using expand eg
https://graph.microsoft.com/v1.0/me/mailfolders?expand=childFolders
This would for instance give you subfolders of the Inbox Folder in the ChildFolders property eg
"id": "AQMk",
"displayName": "Inbox",
"childFolders@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('150bb06c-1c9a-4ac2-8b55-8cf15854b555')/mailFolders('AQ-0Y6jBNnUCxQousINAAAAIBDAAAAA%3D%3D')/childFolders",
"childFolders": [
{
"id": "AAA=",
"displayName": "aa",
"parentFolderId": "AQM==",
"childFolderCount": 0,
"unreadItemCount": 178,
"totalItemCount": 209,
"isHidden": false
},
There are a few different ways of solving your problem if all you wanted to do was create subfolders of the Inbox folder (or other wellknown folder) then if you changed line 36 to
$Uri = "https://graph.microsoft.com/v1.0/users/$mailbox/mailFolders/Inbox/ChildFolders"
all the logic in your script should work okay else you should find the FolderId of the parentFolder you want to create those folders under