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

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

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

image

 

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

 

image

 

 

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%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

image

 

Download Script -

CustomRootFolder.ps1

Great !!

You learnt how to create Custom root folders in all the mailboxes

 

Regards

Satheshwaran Manoharan

Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Richard Mueller edited Revision 4. Comment: Modified title casing, added tags

  • Patris_70 edited Revision 3. Comment: deleted (en-US) title

  • Carsten Siemens edited Revision 1. Comment: fixed typo

Page 1 of 1 (3 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Great Article Thanks!

  • Carsten Siemens edited Revision 1. Comment: fixed typo

  • greate

  • Patris_70 edited Revision 3. Comment: deleted (en-US) title

  • Richard Mueller edited Revision 4. Comment: Modified title casing, added tags

Page 1 of 1 (5 items)