• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Create new Outlook folders using PowerShell

Slipstick Systems

› Outlook › Create new Outlook folders using PowerShell

Last reviewed on July 2, 2021     8 Comments

I have a PowerShell sample to delete folders from Outlook and user asked how to use PowerShell to create folders. The PowerShell samples on this page create subfolders in the Inbox, or, by changing one line, add the folders to the root of the mailbox, at the same level as the Inbox.

The first PowerShell has the folder name in the Folders.Add line. If you need more than one folder, repeat the line. However, it is generally much easier to create a text file with one folder name per line than to copy and edit each line. The second set of PowerShell scripts use a text file for the folder names.

folders added using powershell

To add the folder at the same level as the Inbox, change this line:
$Folder.Folders.Add("Scripts")
to
$Folder.Parent.folders.Add("Scripts")

$olApp = new-object -comobject outlook.application
$namespace = $olApp.GetNamespace("MAPI")

# Get Inbox
$Folder = $namespace.GetDefaultFolder(6)

# Repeat this line as needed, changing the folder name in each line
$Folder.Folders.Add("Scripts")

# End Inbox 
$olApp.Quit | Out-Null
[GC]::Collect()

 

Create subfolders using a list of filenames

This PowerShell script reads the folder names from a text file. Use this is you need to frequently create new folders as the text file is generally easier to update.

To add the folders at the same level as the Inbox, change this line:
$Folder.Folders.Add($subfolder)
to
$Folder.Parent.folders.Add($subfolder)

Don't forget to change the path to the text file!

Enter your folder names in a text file, one name per line.
text file containing the folder names

$olApp = new-object -comobject outlook.application
$namespace = $olApp.GetNamespace("MAPI")
$Folder = $namespace.GetDefaultFolder(6)

$addnewFolders= New-Object System.IO.StreamReader("D:\Documents\newfolders.txt")
while (($subfolder =$addnewFolders.ReadLine()) -ne $null)
{
$Folder.Folders.Add($subfolder)
}

$addnewFolders.Dispose() 
$olApp.Quit | Out-Null
[GC]::Collect()

Like the script above, this PowerShell script reads the folder names from a text file. It just uses a different method to read the text file.

$olApp = new-object -comobject outlook.application
$namespace = $olApp.GetNamespace("MAPI")

$Folder = $namespace.GetDefaultFolder(6)

foreach($subfolder in Get-Content "D:\Documents\newfolders.txt") {
$Folder.Folders.Add($subfolder)
}

$olApp.Quit | Out-Null
[GC]::Collect()

Add folders to a secondary mailbox in your profile

The scripts above work with the default data file; to add the folders to a secondary data file in your profile, you need add another line to identify the data file. You'll also need ot refer to the parent folder by name.

$olApp = new-object -comobject outlook.application
$namespace = $olApp.GetNamespace("MAPI")
$Folders = $namespace.Folders.Item("alias@domain.com")

#parent folder
$Folder = $Folders.Folders.Item("Inbox")

foreach($subfolder in Get-Content "D:\Documents\newfolders.txt") {

$Folder.folders.Add($subfolder)
  
}
$olApp.Quit | Out-Null
[GC]::Collect()

 

Delete the folders using PowerShell

If you need to delete the folders you added, this PowerShell will read the text file and delete the folders. This script moves the folders to the deleted items folder. To delete them from the Deleted Items folder, change 6 to a 3 in this line:
$Folder = $namespace.GetDefaultFolder(6)

$olApp = new-object -comobject outlook.application
$namespace = $olApp.GetNamespace("MAPI")

# delete subfolders from Inbox folder
$Folder = $namespace.GetDefaultFolder(6)

foreach($subfolder in Get-Content "D:\Documents\newfolders.txt") {
$Folder.Folders.item($subfolder).Delete()
}

$olApp.Quit | Out-Null
[GC]::Collect()

 

Using PowerShell Scripts

To open the PowerShell IDE, type powershell on the start menu and click on Windows PowerShell ISE when the PowerShell app is found. Paste the script in the editing window.

powershell ise

Note: This PowerShell script will not work with the Windows Store version of Office. You'll need to use the macro version if you have the Windows store version of Office installed.

Saving PowerShell Scripts

If you want to save the script as a .ps1 file, paste it into Notepad and save it with the extension .ps1. To open it in the PowerShell IDE, type powershell on the start menu and click on Windows PowerShell ISE when the PowerShell app is found. Paste the script in the editing window.

To use it, you need to allow local scripts by running this command:

Set-ExecutionPolicy RemoteSigned

To run your saved .ps1 file, right-click on the script and choose Run with PowerShell.

More Information

A VBA macro that creates folders from a CSV list of filenames is here: Create Outlook Folders from a List of Folder Names

To delete folders, see Delete folders using a macro or PowerShell

Create new Outlook folders using PowerShell was last modified: July 2nd, 2021 by Diane Poremsky
Post Views: 69

Related Posts:

  • Delete folders using a VBA Macro or PowerShell
  • Open Outlook Folders using PowerShell or VBScript
  • Use PowerShell to Bulk Change Contacts
  • Use PowerShell to Export and Import Categories

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Comments

  1. Jake says

    June 29, 2023 at 11:55 am

    Hello,

    How can I add a sub-sub-sub folder to a shared mailbox?

    So Inbox>Sub1>Sub2>Sub3 with Sub3 being the folder I want to create from a notepad list.

    I can currently add a Sub1 using your 'Add folders to a secondary mailbox in your profile' script.
    TIA.

    Reply
  2. GATE says

    January 20, 2023 at 5:57 am

    hello, thanks for the script, did you know witch module we have to import? thanks

    Reply
  3. PowerShelly says

    January 6, 2023 at 3:17 am

    Unfortunately I have not figured out how to create a sub-sub folder?

    Just using "\" or "/" in the name doesn't work.
    Maybe this could be extended here?

    Reply
    • Diane Poremsky says

      January 8, 2023 at 9:55 pm

      You need to "walk" the folders.

      $Folder = $namespace.GetDefaultFolder(6).Folders("parent folder name")

      # Repeat this line as needed, changing the folder name in each line
      $Folder.Folders.Add("Scripts")

      That would create subfolder at Inbox\parent folder name\scripts

      Reply
  4. PowerShelly says

    January 6, 2023 at 3:15 am

    Thank you very much for the post.

    On my device (no admin rights - Win10 20H2) there is an error with the line MAPI.

    Die Methode kann nicht aufgerufen werden. Der Methodenaufruf wird in diesem Sprachmodus nur für Kerntypen unterstützt.
    The method cannot be called. Method invocation is supported in this language mode only for core types.
    In Zeile:2 Zeichen:1
    + $namespace = $olApp.GetNamespace("MAPI")
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage
     
    Es ist nicht möglich, eine Methode für einen Ausdruck aufzurufen, der den NULL hat.
    In Zeile:5 Zeichen:1
    + $Folder = $namespace.GetDefaultFolder(6)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull
    

    For me the following commands works:

    # Outlook Connection
    $Outlook = New-Object -ComObject Outlook.Application
    
    ## Connect to Folder 
    $Folder = $Outlook.session.GetDefaultFolder(6);
    
    Reply
  5. PowerShelly says

    January 6, 2023 at 3:12 am

    Thank you very much for the post.

    On my device (no admin rights - Win10 20H2) there is an error with the line MAPI.

    For me the following commands works:

    # Outlook Connection
    $Outlook = New-Object -ComObject Outlook.Application
    
    ## Connect to Folder 
    $Folder = $Outlook.session.GetDefaultFolder(6)     
    
    Reply
  6. SBZB says

    August 5, 2021 at 5:28 pm

    This is awesome, thank you.

    Reply
  7. Dark Knight says

    July 3, 2021 at 1:45 am

    Thank you!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 5

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Sync Issues and Errors with Gmail and Yahoo accounts

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.