Create folder(s) in user(s) mailboxes using EWS

A PowerShell script that will create folders (one or more) in users’ mailboxes using EWS.

 
 
 
 
 
(0)
4,482 times
Add to favorites
Exchange
8/24/2016
E-mail Twitter del.icio.us Digg Facebook
  • -ParentFolder
    1 Posts | Last post October 01, 2019
    • If the folder I want to create is in a nested folder structure, i.e create the folder ABC under Personal\Company resulting in Personal\Company\ABC
      
      What is the syntax for the -ParentFolder?
      
      Thanks
      Ian
  • Error Unauthorized
    3 Posts | Last post September 06, 2019
    • Hello, 
      I'm running the script but get this error.
      Error occurred attempting to bind to folder: Exception calling "Bind" with "2" argument(s): "The request failed. The remote server returned an error: (401) Unauthorized."
      Error occurred attempting to bind to folder: Exception calling "Bind" with "3" argument(s): "Value cannot be null.
      Parameter name: folderId"
      
      Thanks
    • Did you find a solution for this error?
    • -Credentials (Get-Credential)
      
      ^ Use your global admin account.  Most Office 365 implementations have an o365Global account, something that has full control of all mailboxes.
  • Mailboxes.txt
    2 Posts | Last post September 06, 2019
    • When i use the txt file it says c:\source\mailboxes.txt : error occurred during autodiscover: Exception calling "AutodiscoverUrl" with "1" argument(s):
      "The e-mail address is formed incorrectly."
      
      When I specify the email address explicitly without using a txt file it works
      
      Any ideas on this one
    • -EwsUrl https://outlook.office365.com/EWS/Exchange.asmx
      
      ^ Sometimes the autodiscover redirects are too deep and the system just blocks the action for some security blah blah, use the EwsUrl switch, I've supplied the URL for Exchange Online (office 365).
  • Does this script account for the archive parameter?
    2 Posts | Last post July 17, 2018
    • The Archive parameter does not seem to function in this script and in looking at the code it looks as if it takes the Archive parameter, but does nothing with it.  Does anyone know how to get this code to work with the Archive mailbox?
    • I was able to get the Archive parameter to work by adding some additional code. Basically, the Archive parameter was empty code - it never called anything. Below, I just added to the function for processing the mailbox and added an If statement.
      
          # Bind to root folder	
          $mbx = New-Object Microsoft.Exchange.WebServices.Data.Mailbox( $Mailbox )
          $Folder = $Null
          if ([String]::IsNullOrEmpty($ParentFolder))
          {
              $ParentFolder = "wellknownfoldername.Inbox"
          }
          if ($ParentFolder.ToLower().StartsWith("wellknownfoldername."))
          {
              # Well known folder specified (could be different name depending on language, so we bind to it using WellKnownFolderName enumeration)
              $wkf = $ParentFolder.SubString(20)
              LogVerbose "Attempting to bind to well known folder: $wkf"
              $folderId = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::$wkf, $mbx )
              $Folder = ThrottledFolderBind($folderId)
          }
      ###New code addition starting here...
      	if ($Archive)
      	{
      	    $folderId = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::ArchiveMsgFolderRoot, $mbx )
              $Folder = ThrottledFolderBind($folderId)
              if ($Folder -and ($ParentFolder -ne "\"))
              {
      	        $Folder = GetFolder($Folder, $ParentFolder, $false)
              }
      	}
      ###End new code addition
          else
          {
              $folderId = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot, $mbx )
              $Folder = ThrottledFolderBind($folderId)
              if ($Folder -and ($ParentFolder -ne "\"))
              {
      	        $Folder = GetFolder($Folder, $ParentFolder, $false)
              }
          }