PowerShell: Update mailbox folder (add/delete properties, change name, purge)

A PowerShell script that uses EWS to update mailbox folders.  You can add or delete most MAPI properties, change name, or purge/delete the folder(s).This script requires the EWS Managed API to be installed on the machine on which it is run.  The only other requirement is an Excha

 
 
 
 
 
5 Star
(3)
Add to favorites
6/28/2019
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Retention Tags?
    2 Posts | Last post November 28, 2018
    • Can the script be used to add Personal Retention Tags to non-standard folders using the '-AddFolderProperties' parameter? I'd like to create a scheduled task that can create the required Archive folders, then apply the retention tags to those folders so everybody has the same tags applied to their archive folders without requiring user intervention.  We are currently using Enterprise Vault for archiving and retention but would like to eliminate it. Finding a way to stamp the folders is the key to getting rid of EV.
    • It will work for most MAPI properties so long as they are not protected (e.g. read-only), which some are.  I don't believe retention tags are protected, so there shouldn't be an issue writing them.
  • "-Purge" option listed but missing
    2 Posts | Last post November 28, 2018
    • Under "Parameters" on the description page I see a "-Purge" option. There is no such option in the code itself. The function described for this parameter is exactly what I need to do, and I am a little confused as to why it is missing. Is this the result of an upgrade or a code revision?
    • This option is in the code, and was one of the early features of the script.  The function in question is PurgeFolder, which I have just confirmed is present.  Not sure why it would be missing for you.
  • Purge changing Schema Version?
    2 Posts | Last post April 26, 2017
    • Is there a reason for this:
      
          # Creates and returns an ExchangeService object to be used to access mailboxes 
          $exchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1 
          if ($Purge) 
          { 
              $exchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1 
          } 
          LogVerbose "Requesting schema version $($exchangeVersion.ToString())" 
          $exchangeService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchangeVersion)
      
      We still use Exchange2007_SP1 so to run the Purge command I had to flip the "Exchange2010_SP1" to "Exchange2007_SP1" for it to effectively connect to the mailbox.
    • Yes, there was a reason.  However, given your example, the logic for the reason is faulty.  The difference in version is because 2010SP1 and higher supports the Folder.Empty call, while earlier versions don't.  The script will call Folder.Empty if the requested server version is high enough, otherwise it will purge the folder items in batches.
      
      Thanks for pointing this out.  I'll update the script when I get a chance so that it works as I intended!
  • Custon Outlook Folder Name Change
    1 Posts | Last post April 07, 2017
  • I am deleting sub-folders under Archive Folders
    2 Posts | Last post December 09, 2016
    • 
      .\Update-Folders.ps1 -Mailbox myemail@contoso.com -FolderPath "\Archive Folders" -ProcessSubFolders -Delete
      
      I am getting this error
      Exception calling "Bind" with "2" argument(s): "The Url property on the ExchangeService object must be set."
      At C:\temp\Update-Folders.ps1:1084 char:13
      +             $rootFolder = [Microsoft.Exchange.WebServices.Data.Folder ...
      +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
          + FullyQualifiedErrorId : ServiceLocalException
      Unable to bind to root folder.  No further processing possible
      
    • Set the EWS URL by specifying the -ewsurl parameter.
  • has anyone tested this in Exchange Online accounts?
    2 Posts | Last post October 20, 2016
    • We have a customer that has certain clients that he needs to purge emails for on a daily basis. This script seems promising but so far everyone seems to be using it On Prem. Can someone confirm this works with Exchange Online accounts before we even attempt to try this?
    • It works with Exchange Online.
  • Purge failing
    2 Posts | Last post October 06, 2016
    • Thanks so much for the script, unfortunately it is not working 100%.
      
      I can delete an empty folder, but not purge the items.
      
      Exchange 2010 sp3, EWS API 2.2
      
      "Failed to purge (Foldername)"
      
      Any help? Thanks
    • the $Folder.Load( ) at line 610 needs to be moved to the bottom of the closure (line 615) as $Folder.ChildFolderCount isnt getting updated for some reason when its inside the Try
      
      also, if you use purge and the folder is already empty you can get an error so if you change line 604 to if (($Purge) -And ($Folder.TotalCount -gt 0)) then that will stop happening as well
  • Purge Script Not working.
    2 Posts | Last post April 21, 2016
    • Hi All,
      
      I am trying to delete certain folders with the script. Deleting empty folders is working with no issues, however when trying to delete the items first using the -purge command, we receive “Failed to purge FolderName”.
      
      Running the following command:
      .\Update-Folders.ps1 -Mailbox “smtpaddress” -FolderPath “Testing123″ -Purge -Verbose
      This is does work for my current admin account which I am running it as or against other mailboxes with the -Impersonate command.
      
      Thank you,
      Stephen Miserez
    • I agree, even on the current / self Administrator account mailbox, the purge command is failing.  Delete works only if the folder is empty.  Help? 
  • Exchange 20102 에서 MAPI 아이디 어디서 보나요
    1 Posts | Last post March 16, 2016
    • - Exchange 20102 에서 MAPI 아이디 어디서 보나요
      - 찾으려는 이유 : Exchange에 생성된 빈폴더 일괄 삭제가 필요
      - MAPI ID : 0x36160102
      
      - 연락처 010-6275-8423 으로 연락 부탁드립니다.