Share via


Exchange 2010: Create a Custom Root Folder in all the Mailboxes (Bulk)

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

Important

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

http://careexchange.in/wp-content/uploads/2012/02/image_thumb58.png

Prerequisites -

Download and Install in your Server

Exchange Web Services Managed API

http://www.microsoft.com/en-us/download/details.aspx?id=28952

Add the User to the “ApplicationImpersonation” Role assignment

New-managementroleassignment –Role “ApplicationImpersonation” –user administrator

http://careexchange.in/wp-content/uploads/2012/02/image_thumb59.png

Now you can go ahead

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%22)
# 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

http://careexchange.in/wp-content/uploads/2012/02/image_thumb60.png

Download Script

CustomRootFolder.ps1