SOLVED

Remove-MgUserMailFolder not working because of invalid ID

Copper Contributor

Hello,

 

I've been asked to delete an Outlook folder called Promo across the whole enterprise. 

Get-MgUserMailFolder -UserId email address removed for privacy reasons -All shows all Outlook folders for me and Promo is in there.
 
Remove-MgUserMailFolder -MailFolderId Promo-UserId email address removed for privacy reasons returns the error 
Remove-MgUserMailFolder : Id is malformed
 
GET /users/email address removed for privacy reasons/mailFolders/Promo ==>I get the following error
 
error": {
        "code": "ErrorInvalidIdMalformed",
        "message": "Id is malformed.",
 
How can I remove a folder named "Promo" across the enterprise using 
Remove-MgUserMailFolder -MailFolderId Promo-UserId email address removed for privacy reasons
 
Many thanks,
2 Replies
best response confirmed by flourishingnixcomets (Copper Contributor)
Solution
Well you need to provide the ID of the folder, not its name. You can obtain the ID value from the first cmdlet, Get-MgUserMailFolder, it will look something like this: AAMkAGU2MWM5NzU0LWY3MmQtNGI3OS1hNDVlLTBkMzI3OWVlNWIzZgAuAAAAAAChKSJAhlnUTIHtKSso30ThAQBIPfDMxyP-RYhY8M8xmAPVAAS8XYnlAAA=
Jees I feel awkward, I have no idea how I missed the trailing =. This worked. Thank you.
1 best response

Accepted Solutions
best response confirmed by flourishingnixcomets (Copper Contributor)
Solution
Well you need to provide the ID of the folder, not its name. You can obtain the ID value from the first cmdlet, Get-MgUserMailFolder, it will look something like this: AAMkAGU2MWM5NzU0LWY3MmQtNGI3OS1hNDVlLTBkMzI3OWVlNWIzZgAuAAAAAAChKSJAhlnUTIHtKSso30ThAQBIPfDMxyP-RYhY8M8xmAPVAAS8XYnlAAA=

View solution in original post