How to Create Folders with Year, Month, and Day Using PowerShell?

In this tutorial, I will explain how to create folders using PowerShell that are dynamically named based on the current year, month, and day. This can be incredibly useful for organizing files and folders by date. I recently needed to implement this myself to keep track of daily reports at my company, located in Seattle.

Create Folders with Year, Month, and Day Using PowerShell

To create a folder with the current date in PowerShell, we can use the Get-Date cmdlet and New-Item cmdlet. Here’s a simple example:

$folderName = Get-Date -Format "yyyy-MM-dd"  
New-Item -ItemType Directory -Path "C:\Reports\$folderName"

This script does the following:

  1. Gets the current date and formats it as “yyyy-MM-dd” (e.g. “2025-03-31”)
  2. Creates a new folder with that date as the name in the “C:\Reports” directory

To break it down further:

  • Get-Date -Format "yyyy-MM-dd" retrieves the current date and formats it in the specified format.
  • New-Item -ItemType Directory creates a new directory (folder)
  • -Path specifies the full path where the folder should be created, referencing the $folderName variable

The path in the above command will work in the Windows OS.

I am using a macOS, and you can provide the path like below:

$folderName = Get-Date -Format "yyyy-MM-dd"  
New-Item -ItemType Directory -Path "/Users/bijay/Downloads/$folderName"

I executed the above PowerShell script, and you can see the exact output in the screenshot below:

Create Folders with Year, Month, and Day Using PowerShell

Check out Create a Folder with the Current Date using PowerShell

Create Year and Month Subfolders Using PowerShell

In my case, I needed to organize the folders further by year and month. To accomplish this, we can tweak the script to:

  1. Create a folder for the current year if it doesn’t exist
  2. Create a subfolder in the year folder for the current month if it doesn’t exist
  3. Create the dated folder inside the month folder

Here’s the modified PowerShell script:

$year = Get-Date -Format "yyyy"
$month = Get-Date -Format "MM"  
$day = Get-Date -Format "dd"

$basePath = "C:\Reports"
$yearPath = Join-Path $basePath $year
$monthPath = Join-Path $yearPath $month

New-Item -ItemType Directory -Path $yearPath -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Path $monthPath -ErrorAction SilentlyContinue  

$folderName = "{0}-{1}-{2}" -f $year,$month,$day
$folderPath = Join-Path $monthPath $folderName
New-Item -ItemType Directory -Path $folderPath

This will generate a folder structure like:

C:\Reports\
    2025\
        03\
            2025-03-31\

A few notes on the updated script:

  • We retrieve the year, month, and day components separately using Get-Date for more flexibility
  • Join-Path is used to build the full paths by combining the base path, year, month, and day
  • -ErrorAction SilentlyContinue suppresses errors if the directory already exists
  • The folder name is constructed using the -f string format operator to avoid long concatenations

Read Create Files with Content Using PowerShell

Running the Script Daily

We can schedule the PowerShell script to run daily using Task Scheduler on Windows to fully automate the process. Here are the high-level steps:

  1. Save the script with a .ps1 extension (e.g. CreateDatedFolder.ps1)
  2. Open Task Scheduler and create a new task
  3. Configure the task with the following settings:
    • Run whether the user is logged in or not
    • Trigger: Daily at a specified time
    • Action: Start a program
      • Program/script: powershell.exe
      • Arguments: -File "C:\path\to\CreateDatedFolder.ps1"
  4. Save the task

Now the script will automatically run each day and create the appropriate year, month, and day folders to keep your files organized chronologically.

Conclusion

In this tutorial, I explained how to create folders with Year, Month, and Day using PowerShell. By using the Get-Date cmdlet to retrieve the current year, month, and day, you can generate a clean folder structure that makes it easy to manage files on a daily basis.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.