none
Create Custom Folder for all Mailboxes RRS feed

  • Question

  • I need help with Exchange Online.  I want to create a custom folder that resides in all users' mailboxes so that I can set a "never delete" retention policy on it.  Typically, mail older than 90 days are deleted unless the users tag them.  I want to make it easier for them by creating a folder that retains email indefinitely.  

    I'm not very good at scripting.  I tried running this:

    $userList = Get-Mailbox -resultsize unlimited

    foreach($user in $userList){

        New-MailboxFolder -Name "Retention Folder" 
    }

    It will ask me to define the parent, but it works.  I want the script to work on all mailboxes in bulk, and for the parent folder to already be defined so it doesn't prompt me.   I want the folder to also sit at the highest level as the Inbox does so it's visible.  

    Any advice is appreciated.  Thank you.

    Tuesday, June 30, 2020 4:38 AM

Answers

  • Hello,

    Following script can be modified for your purpose

    Note that, you need to get the alias list of all mailboxes first as csv file (in this example, users.csv) first and give as the input of the cmdlet

    get-mailbox -ResultSize Unlimited | select -expand alias >c:\tmp\users.csv
    $Users = Get-Content "C:\tmp\users.csv" foreach ($User in ($Users))
    {
        New-MailboxFolder -Parent $user -Name "Retention Folder"
    }


    Regards From: Exchange Online | World of Cloud Computing


    • Edited by ManU PhiliP Tuesday, June 30, 2020 5:20 AM
    • Marked as answer by Pino Gravy Tuesday, June 30, 2020 5:57 PM
    Tuesday, June 30, 2020 5:20 AM

All replies

  • Hello,

    Following script can be modified for your purpose

    Note that, you need to get the alias list of all mailboxes first as csv file (in this example, users.csv) first and give as the input of the cmdlet

    get-mailbox -ResultSize Unlimited | select -expand alias >c:\tmp\users.csv
    $Users = Get-Content "C:\tmp\users.csv" foreach ($User in ($Users))
    {
        New-MailboxFolder -Parent $user -Name "Retention Folder"
    }


    Regards From: Exchange Online | World of Cloud Computing


    • Edited by ManU PhiliP Tuesday, June 30, 2020 5:20 AM
    • Marked as answer by Pino Gravy Tuesday, June 30, 2020 5:57 PM
    Tuesday, June 30, 2020 5:20 AM
  • Thank you so much for the quick reply.  I'll give it a shot tonight.  
    Tuesday, June 30, 2020 5:21 AM
  • ManU, I'm still getting prompted for the parent.  This is what it says when I run it.  

    cmdlet New-MailboxFolder at command pipeline position 1
    Supply values for the following parameters:
    Parent:

    I modified what you have to this:

    get-mailbox -ResultSize Unlimited | select -expand alias >c:\temp\test.csv

    $Users = Get-Content "C:\temp\test.csv" foreach ($User in ($Users))
    {
        New-MailboxFolder -Parent $user -Name "Retention Folder"
    }

    I only slightly changed the location and name of the .csv file.  The csv file only has my alias in it that looks like this "firstname.lastname"

    It works if I enter my email at the prompt.

    Tuesday, June 30, 2020 5:48 AM
  • Okay, I got the script to work.  I place the foreach command on a new line.  It looks like this now:

    get-mailbox -ResultSize Unlimited | select -expand alias >c:\temp\users.csv

    $Users = Get-Content "C:\temp\users.csv" 
    foreach ($User in ($Users))
    {
        New-MailboxFolder -Parent $user -Name "Retention Folder"
    }


    Now the error returned says that the mailboxes doesn't exist.  It will go down the list and I can see the names, but each time it will say, "The specified mailbox "firstname.lastname" doesn't exist."  The weird part is when it got to my name, it worked, but only for me.    

    I'm close.  


    Tuesday, June 30, 2020 7:38 AM
  • Okay I lost hope.  According to this, https://docs.microsoft.com/en-us/powershell/module/exchange/new-mailboxfolder?view=exchange-ps, "Administrators can't use this cmdlet to create folders in other mailboxes (the cmdlet is available only from the MyBaseOptions user role)."

    Explains why it only works for me.  Bummer.   I'm not sure what to do now.  I can send instructions to my users on how to create their own folder with a "never delete" retention tag, but I was hoping to create something more consistent and standard.
    Tuesday, June 30, 2020 8:42 AM
  • Hello,

    I have a great news for you. I just finished a blog article to make your task easy. If you own an Azure Tenant, my article with help you to create the folder in all your mailboxes. Just get the email addresses and other details as explained in the blog and create the folder across your tenant. I am using Graph API here and will be helpful in your future such requirements too

    http://cloudcompute.info/create-custom-folder-in-exchange-online-mailboxes-using-graph-api-using-windows-powershell/


    Regards From: Exchange Online | World of Cloud Computing

    Tuesday, June 30, 2020 8:09 PM