The New-MgUserMailFolderChildFolder cmdlet allows administrators to create child folders in a user's mailbox. This is particularly useful for organizing emails and improving workflow efficiency.
New-MgUserMailFolderChildFolder -UserId <String> -MailFolderId <String> -BodyParameter <Hashtable>
Note:: To work with New-MgUserMailFolderChildFolder cmdlet, you need MailFolderIDs which can be got using Get-MgUserMailFolder cmdlet.
The child folder name should be passed to the -BodyParameter as hashtable.
$params = @{
displayName = "ProjectA"
}
New-MgUserMailFolderChildFolder -UserId "user@domain.com" -MailFolderId "AQMkADAwATM3ZmYAZC1lYwEyLTk2MTAtMAAAM_Q5fOAAA=" -BodyParameter $params
Loop through all the folders and execute New-MgUserMailFolderChildFolder for each of them.
$folders = @("ProjectB", "ProjectC", "ProjectD")
foreach ($folder in $folders) {
$params = @{
displayName = $folder
}
New-MgUserMailFolderChildFolder -UserId "user@domain.com" -MailFolderId "AQMkADAwATM3ZmYAZC1lYwEyLTk2MTAtMDACLTAwCg_Q5fOAAA=" -BodyParameter $params
}
Import the folder names from CSV file and execute New-MgUserMailFolderChildFolder for each data row.
CSV File
The CSV file should have the following structure.
FolderName
ProjectE
ProjectF
ProjectG
PowerShell Script:
$csv = Import-Csv -Path "C:\path\to\folders.csv"
foreach ($row in $csv) {
$params = @{
displayName = $row.FolderName
}
New-MgUserMailFolderChildFolder -UserId "user@domain.com" -MailFolderId "AQMkADAwATM3ZmYAZC1lYwEyLTk2MTAtMDACLTAAAAM_Q5fOAAA=" -BodyParameter $params
}
You can also pass additional folder properties, if necessary.
$params = @{
displayName = "Important"
isHidden = $true
}
New-MgUserMailFolderChildFolder -UserId "user@domain.com" -MailFolderId "AQMkADAwATM3ZmYAZC1lYwEyLTk2MTAtMDACLsUQAFHkKlAAAM_Q5fOAAA=" -BodyParameter $params
Cause: The specified MailFolderId does not exist.
Solution: Verify the MailFolderId and ensure it belongs to the correct user.
Cause: Invalid or expired credentials.
Solution: Re-authenticate using valid credentials.
Cause: Malformed request body.
Solution: Ensure the BodyParameter hashtable is correctly formatted and includes valid properties.
Cause: Insufficient permissions to create folders.
Solution: Ensure the account running the script has the necessary permissions to create folders in the user's mailbox. Mail.ReadWrite is the required Graph API permission
The New-MgUserMailFolderChildFolder cmdlet is a powerful tool for managing and organizing emails in user mailboxes. By creating child folders, administrators and users can improve workflow efficiency and keep their inboxes tidy. Utilizing the cmdlet with proper parameters and understanding potential errors ensures smooth folder management in Microsoft 365 environments.
© m365corner.com. All Rights Reserved. Design by HTML Codex