I need to create a some folders in every single mailbox in our exchange organisation.

Is there a quick way to achieve this with a powershell script?

(note this is not public folders, these folders must exist inside the users mailbox)

  • Pretty sure this is a duplicate, but I am not finding the question that I remember seeing a while back.
    – Zoredache
    Dec 1 '11 at 23:53
  • @Zoredache - same, and my search skills aren't too bad these days. Unfortunately everything I found was prefixed with the word "public" as in public folders. Dec 1 '11 at 23:54
  • I haven't played with it since I don't have 2010 yet, but ExFolders may be able to do something. blogs.technet.com/b/exchange/archive/2009/12/04/3408943.aspx
    – Zoredache
    Dec 2 '11 at 0:08

You can do this with the Exchange Web Services (EWS) API. This script should create a folder in a mailbox (I don't have an E2K10 machine w/ EWS 1.1 installed handy right now so I'm cobbling this together from code samples and memory and hoping it'll actually work-- it looks right). This should work as the basis for a script to iterate through mailboxes creating folders (but since I'm such a PowerShell dunce I'm leaving that up to you):

$MailboxName = "mailbox@domain.com"

$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1)

$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
$aceuser = [ADSI]$sidbind


$folderid = new-object  Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root, $MailboxName)
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folderid)

$NewFolder = new-object Microsoft.Exchange.WebServices.Data.Folder($service)
$NewFolder.DisplayName = "Folder_to_Create"

This script assumes you've got EWS 1.1 installed and are logged-on with a credential that has permission to access the subject mailbox.

  • EWS is certainly installed on some of the servers, because it's being used integration with an external system. I'll give it a go, thanks. Dec 2 '11 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.