Wednesday , October 16 2019

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

 

About Satheshwaran Manoharan

Satheshwaran Manoharan is an Microsoft Office Server and Services MVP , Publisher of Azure365pro.com. Specialized in Office365 / Microsoft Exchange / Virtualization , Sathesh is an Messaging Expert supporting/Designing/Deploying many medium size businesses to large enterprises when it comes to Corporate messaging and Virtualization Infrastructure

Check Also

Disabling AuthGSSAPI on Receive Connector of Exchange Server

Submitting Messages on Port 587 from F5 SMTP Mailer failing with AUTH GSSAPI Remote(SocketError) when ...

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!

  3. Good One Sathesh..

  4. This post was very helpfull. Thank you, Sathesh.

  5. Yennifer Ricaurte

    Hello I would like to configure this script so that no user can delete the folder

    • Satheshwaran Manoharan

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

  6. Hurrah! At last I got a web site from where I can actually get helpful information concerning my study and knowledge.

  7. Is there a way of scripting this to add a home page by default also?

    • Satheshwaran Manoharan

      Adding a home page ? where ?

      • 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.

  8. 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

  9. This works perfect! Thanks! Is there a way to create a sub-folder within the folder that is created in the same script?

  10. 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.

  11. 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?

  12. 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.

  13. 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 .

  14. How do I create new task folder on outlook using this script.

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

  16. 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!

  17. internet marketing solution

    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.

  18. pakistan video 2014

    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.

  19. jual kerajinan dari bambu

    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.

  20. 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 ?

    • Satheshwaran Manoharan

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

  21. 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

  22. 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

  23. Is it possible to push the folder to an ad group and not to all mailboxes or only one mailbox?

  24. 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.

  25. Hello to every one, it’s genuinely a fastidious
    for me to visit this web page, it consists of valuable Information.

Leave a Reply

Your email address will not be published.