Download Script –
Refer the below link for the original script , and Customized it a little
http://blogs.msdn.com/b/akashb/archive/2011/07/23/creating-folder-using-ews-managed-api-1-1-from-powershell.aspx
And Please Test in your lab – Before proceeding into your live Environment
There is a a good script where we can use to create a Custom root Folder in all the Mailboxes in your environment.
Were we can create Custom Folders Like below for single mailbox and for all the mailboxes in Bulk
Prerequisites –
Download and Install in your Server
Exchange Web Services Managed API
http://www.microsoft.com/download/en/details.aspx?id=13480
——
Add the User to the “ApplicationImpersonation” Role assignment
New-managementroleassignment –Role “ApplicationImpersonation” –user administrator
Now you can go ahead and use the script—
Please Try for the One Mailbox – And Please Test in your lab – Before proceeding into your live Environment
[string]$info = "White" # Color for informational messages [string]$warning = "Yellow" # Color for warning messages [string]$error = "Red" # Color for error messages [string]$LogFile = "C:\Temp\Log.txt" # Path of the Log File function CreateFolder($MailboxName) { Write-host "Creating Folder for Mailbox Name:" $MailboxName -foregroundcolor $info Add-Content $LogFile ("Creating Folder for Mailbox Name:" + $MailboxName) #Change the user to Impersonate $service.ImpersonatedUserId = new-object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress,$MailboxName); #Create the folder object $oFolder = new-object Microsoft.Exchange.WebServices.Data.Folder($service) $oFolder.DisplayName = $FolderName #Call Save to actually create the folder $oFolder.Save([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::msgfolderroot) Write-host "Folder Created for " $MailboxName -foregroundcolor $warning Add-Content $LogFile ("Folder Created for " + $MailboxName) $service.ImpersonatedUserId = $null } #Change the name of the folder $FolderName = "Customer Folder Name" Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\1.1\Microsoft.Exchange.WebServices.dll" $service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1) # Set the Credentials $service.Credentials = new-object Microsoft.Exchange.WebServices.Data.WebCredentials("Administrator","Type your Password Here","careexchange.in") # Change the URL to point to your cas server $service.Url= new-object Uri("https://localhost/EWS/Exchange.asmx") # Set $UseAutoDiscover to $true if you want to use AutoDiscover else it will use the URL set above $UseAutoDiscover = $false $a = get-mailbox $a | foreach-object { $WindowsEmailAddress = $_.WindowsEmailAddress.ToString() #if ($UseAutoDiscover -eq $true) { # Write-host "Autodiscovering.." -foregroundcolor $info #$UseAutoDiscover = $false $service.AutodiscoverUrl($WindowsEmailAddress) #Write-host "Autodiscovering Done!" -foregroundcolor $info # Write-host "EWS URL set to :" $service.Url -foregroundcolor $info # } #To catch the Exceptions generated # trap [System.Exception] # { # Write-host ("Error: " + $_.Exception.Message) -foregroundcolor $error; # Add-Content $LogFile ("Error: " + $_.Exception.Message); # continue; # } CreateFolder($WindowsEmailAddress) }
Do the Edits Required in the Script —
****
msgfolderroot denotes the Root of the Mailbox , If you specify inbox for example it creates the folder below the inbox
****
Change your
User name – Password – Domain Name –
****
$a = get-mailbox denotes all the mailbox
To Run for a single mailbox (use the alias)
$a = get-mailbox “User1”
Save it a Notepad and Rename it to .ps1 file
And Open Power shell locate your powershell into the folder you saved the script
.\create.ps1 for example
Download Script –
Great !!
You learnt how to create Custom root folders in all the mailboxes