27.5 C
Dubai
Tuesday, November 29, 2022

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

 Download Script –

CustomRootFolder.ps1

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/download/en/details.aspx?id=13480

——

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")

# 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

 

Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Specialized in Microsoft Azure - Office 365 / Microsoft Exchange; conducted numerous projects worldwide in designing, supporting, and implementing messaging and virtualization infrastructure for medium-sized and large enterprises. Further, I am a Cloud Architect and Technical Advisor for various start-ups.

Related Articles

35 COMMENTS

  1. your post is really good and informative. i’m surprised that your post has not gotten any. good quality, genuine comments. you have done a great job by posting this article. thanks!!!

  2. magnificent post, very informative. I wonder why the
    other experts of this sector don’t notice this. You must continue your writing. I’m sure, you have a huge readers’ base already!

    • I don’t think a script available for that. You have to use “Managed Folders” to achieve the same

      • What I need is to add is on the Home Page tab of the folder property our old Public folder OWA location and have the ‘Show home page by default for this folder’ be checked off.
        We have moved to a new domain and will not import the public folders from the old domain to the new one but still want users to be able to access the old Public folders until we have it all moved to Sharepoint.

  3. Sathesh,

    Great work on the script, it will really serve a good purpose here in my environment. I am running into two error message that maybe you can point me in the right direction on how to correct. “Exception calling “AutodiscoverUrl” with “1” argument(s): “The Autodiscover service couldn’t be located.”” and “Exception calling “Save” with “1” argument(s): “The request failed. The remote server returned an error: (401) Unauthorized.””. What rights are required on the mailbox in order to create a root folder?

    Thanks for your hard work on this script.

    Stan

  4. I ran the script after making the edits and it said it was successful but the folder is not showing up in Outlook or in OWA. When I rerun the script it said that a folder with the specified names already exists. Am I missing something?

    Thanks for the help. This script is exactly what I need.

  5. Thanks for the update.

    Two questions.

    How can this be modified to create multiple root folders?

    Can permissions be set on the folders so the folder itself cannot be deleted?

  6. Thanks Sir for a post. Can you please guide us to run this code in loop.

    I want to create 100 folders in inbox or root.

  7. Hi,

    I am getting below error while running this script :

    Exception calling “Save” with “1” argument(s): “The request failed. The remote server returned an error: (403) Forbidden.”
    At C:\Users\exadm\Desktop\createfolder.ps1:20 char:18
    + $oFolder.Save <<<< ([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::msgfolderroot)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

    would you help me , please .

  8. Everything is very open with a clear description off the
    challenges. It was truly informative. Yourr site is useful.
    Many thanks for sharing!

  9. Thanks for a marvelous posting! I definitely enjoyed reading it, you might be a great author.I will remember to bookmark
    your blog and will often come back sometime soon.
    I want to encourage you to continue your great job, have a nice holiday weekend!

  10. Personal information should never be solicited unless it is
    absolutely necessary to some service the website offers.
    Set up profiles on all social media sites to strengthen the levels of
    communication that you have with your internet marketing audience.
    We should definitely learn from our own mistakes, but learning how others succeeded is important, too.

  11. If some one wishes expert view about blogging afterward i
    recommend him/her to go to see this web site, Keep up the nice work.

  12. Some people suggest that you should make the eulogy as personal as
    possible while still maintaining some generalizations to make sure
    that even those that didnt know the deceaced will be moved
    by the speech. This technique requires preparation because no one can predict
    when a question will be asked that provides a good opportunity
    to use a quote to respond. There is nothing hard about writing
    an article for Jet – Spinner.

  13. This is very helpful, will this work in Exchange 2013 ? Is there any way to have the emails automatically deleted after a year or so ?

    • Managed Custom Folder is not supported Exchange 2016 above.
      Root folder creation works. New-inbox rule works. to create outlook rules on each mailbox.

  14. Hello, very nice script. I want to create a subfolder under the contacts folder to sync contacts. Is it possible to change the folder form to contacts?
    Best regards,
    Chris

  15. Hello,
    thanks for the nice script. Works perfect to creates IPM.Post folder.
    Is it possible to create subfolders for contacts with the folder form IPM.Contact?
    Best regards, Chris

  16. Hello Satheshwaran,

    Great work !! Kudos!!

    I have one question, how about if we want to automate this process for all new mailbox being created.
    I have little idea about Scripting Agent and seems it can allow us to achieve same.
    Please share your idea on that.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

× How can I help you?