Using New-MgUserMailFolderChildFolder in Graph PowerShell

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.


Syntax

New-MgUserMailFolderChildFolder -UserId <String> -MailFolderId <String> -BodyParameter <Hashtable>
  • UserId: The unique identifier or User Principal Name (UPN) of the user.
  • MailFolderId: The ID of the parent mail folder.
  • BodyParameter: A hashtable containing the details of the child folder to be created.

Note:: To work with New-MgUserMailFolderChildFolder cmdlet, you need MailFolderIDs which can be got using Get-MgUserMailFolder cmdlet.


Usage Examples

Creating a Single Child Folder

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

Creating Multiple Child Folders

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
}

Creating Child Folders from a CSV File

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
}

Creating a Child Folder with Specific Properties

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

Cmdlet Tips

  • Always ensure you have the correct UserId and MailFolderId before creating folders.
  • Use meaningful names for folders to improve email organization.
  • Utilize CSV import for bulk folder creation to save time and reduce errors.

Use Cases

  • Organizing Project Emails: Create folders for each project to keep related emails together.
  • Personal Email Management: Users can have folders for different categories like Work, Personal, and Finance.
  • Team Collaboration: Create shared folders for team projects and communications.

Possible Errors & Solutions

Error: ResourceNotFound

Cause: The specified MailFolderId does not exist.

Solution: Verify the MailFolderId and ensure it belongs to the correct user.

Error: AuthenticationFailed

Cause: Invalid or expired credentials.

Solution: Re-authenticate using valid credentials.

Error: InvalidRequest

Cause: Malformed request body.

Solution: Ensure the BodyParameter hashtable is correctly formatted and includes valid properties.

Error: AccessDenied

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


Conclusion

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.


Additional Resources:

Microsoft Graph PowerShell Module Documentation
Microsoft Graph API Documentation

Related Articles:

Using Get-MgDirectoryRole in Graph PowerShell
Using Get-MgUserLicenseDetail in Graph PowerShell
Using Find-GraphMgCommand in Graph PowerShell
Connect to Microsoft 365 Using PowerShell
How to Create Bulk Users in Office 365 Using Graph PowerShell?
Create Microsoft 365 Group Using Microsoft Graph PowerShell
Block Microsoft 365 User Using Microsoft Graph PowerShell
Assign Microsoft 365 License Using Graph PowerShell
Microsoft 365 User Management Using Graph PowerShell
Checking Group Membership in Microsoft 365
Bulk Assign Microsoft 365 License
Find Inactive Users in Microsoft 365
Using Powershell Graph Search Query
Using Powershell Graph Filter Query
Using Where-Object In Graph PowerShell
Using Expand Property In Graph PowerShell
Using Select Object In Graph PowerShell
Using -Contains Operator In Graph PowerShell
Add User to Multiple Microsoft 365 Groups Using Graph PowerShell
Get Microsoft 365 User Location Using Graph PowerShell
Import Microsoft 365 Groups from CSV File Using Graph PowerShell
Microsoft 365 Group User Import Using Graph PowerShell

© m365corner.com. All Rights Reserved. Design by HTML Codex