Here is a PowerShell EWS script that will create folders (one or more) in users’ mailboxes. It requires the EWS Managed API to be installed, and if it is to be run against multiple mailboxes then the relevant permissions will need to be granted to the mailboxes (e.g. ApplicationImpersonation).
.\Create-MailboxFolder.ps1 -RequiredFolders "Folder 1;Folder 2"
.\Create-MailboxFolder.ps1 -RequiredFolders "Folder 1;Folder 2"
.\Create-MailboxFolder.ps1 -Mailbox "c:\mailboxes.txt" -RequiredFolders "Folder 1;Folder 2" -ParentFolder "\My Folder" -Impersonate
.\Create-MailboxFolder.ps1 -Mailbox "c:\mailboxes.txt" -RequiredFolders "Folder 1;Folder 2" -ParentFolder "\My Folder" -Impersonate
.\Create-MailboxFolder.ps1 -Credentials (Get-Credential) -Mailbox "c:\mailboxes.txt" -RequiredFolders "Folder 1;Folder 2" -ParentFolder "\My Folder" -Impersonate
.\Create-MailboxFolder.ps1 -Credentials (Get-Credential) -Mailbox "c:\mailboxes.txt" -RequiredFolders "Folder 1;Folder 2" -ParentFolder "\My Folder" -Impersonate
.\Create-MailboxFolder.ps1 -Credentials (Get-Credential) -Mailbox "c:\mailboxes.txt" -RequiredFolders "Folder 1;Folder 2" -ParentFolder "WellKnownFolderName.SentItems" -Impersonate -EwsUrl "https://outlook.office365.com/EWS/Exchange.asmx"
.\Create-MailboxFolder.ps1 -Credentials (Get-Credential) -Mailbox "c:\mailboxes.txt" -RequiredFolders "Folder 1;Folder 2" -ParentFolder "WellKnownFolderName.SentItems" -Impersonate -EwsUrl "https://outlook.office365.com/EWS/Exchange.asmx"
-Mailbox | If present, this is the SMTP address of the mailbox that will be accessed OR it is a path to a text file that contains a list of SMTP addresses (in which case the script will attempt to access all mailboxes in the list). If missing, then the script will try to determine the current user's email address and use that. |
-RequiredFolders | The list of folders to be created (if more than one, separate with a semi-colon e.g. "Folder 1;Folder 2" |
-ParentFolder | If specified, this is the folder in which the required folders will be created. If this parameter is missing, the Inbox folder is used. You can either specify a full path (e.g. "\My Folder") or use the WellKnownFolderName enumeration (the advantage of this is that it won't matter what locale the mailbox is using). |
-FolderClass | When specified, the default item type of the folder will be set to this. If not specified, the default item type is "IPF.Note" |
-Archive | When specified, the mailbox archive is accessed (instead of the main mailbox). |
-Credentials | Will accept PSCredentials for authentication to Exchange (e.g. Get-Credential). This cannot be used with other authentication parameters (e.g. -username). |
-Username | Username to authenticate with Exchange. |
-Password | Password to authenticate with Exchange. |
-Domain | Domain for authentication. |
-Impersonate | Mailbox will be accessed using Impersonation (the authenticating account needs impersonation rights to the mailbox). |
-EwsUrl | The EWS endpoint. If not specified, autodiscover will be used to determine the correct EWS URL. For Office 365, you can use "https://outlook.office365.com/EWS/Exchange.asmx" as the URL. |
-EwsManagedApiPath | The path to the EWS Managed API. The script will search standard locations for the dll, but if you have installed it elsewhere you may need to specify the location. |
-IgnoreSSLCertificate | If present, any SSL certificate errors will be ignored. Useful for testing in a lab with self-signed certificates. |
-AllowInsecureRedirection | If present, autodiscover will accept redirects to insecure addresses. |
-WhatIf | If present, no changes will be written to the mailbox. |
-LogFile | If specified, actions will be logged to this file (the same information is shown in the console). |
-TraceFile | If specified, EWS requests/responses will be logged to this file. This is only useful for debugging. |