How to Create a Folder with Today’s Date and Copy Files to it using PowerShell

Recently, I faced a situation where I needed to automate the process of backing up important files on a daily basis. I wanted the backup folder to be named with the current date for easy organization. It is easy to automate this using PowerShell.

In this tutorial, I will explain how to create a folder with today’s date in PowerShell and then copy files into that newly created folder.

Create a Folder with Today’s Date

To create a folder with today’s date, we can use the PowerShell command New-Item along with the Get-Date cmdlet. Here’s an example:

$folderName = "Backup " + (Get-Date).ToString("yyyy-MM-dd")
New-Item -ItemType Directory -Path "C:\Backups\$folderName"

In this code snippet, we first create a variable called $folderName that combines the prefix “Backup ” with the current date formatted as “yyyy-MM-dd”.

The Get-Date cmdlet retrieves the current date, and the ToString() method formats it according to our specified pattern.

Next, we use the New-Item cmdlet to create a new directory. The -ItemType parameter is set to “Directory” to indicate that we want to create a folder. The -Path parameter specifies the location where the folder should be created.

In this example, the folder will be created in the “C:\Backups” directory with the name stored in the $folderName variable.

For instance, if today’s date is April 30, 2025, the folder created will be named “Backup 2025-30-04”.

Check out Create Folder Structure from CSV using PowerShell

Copy Files to the Date-Named Folder

Once we have created the folder with today’s date, we can proceed to copy files into it. PowerShell provides the Copy-Item cmdlet for this purpose. Here’s an example:

$sourceFiles = "C:\Important\*"
$destinationFolder = "C:\Backups\$folderName"
Copy-Item -Path $sourceFiles -Destination $destinationFolder -Recurse

In this code snippet, we define two variables:

  • $sourceFiles: Specifies the path and pattern of the files to be copied. In this example, it is set to “C:\Important*”, which means all files within the “C:\Important” directory will be copied.
  • $destinationFolder: Specifies the destination folder where the files will be copied to. It uses the $folderName variable we created earlier to set the folder name based on today’s date dynamically.

The Copy-Item cmdlet is then used to copy the files from the source to the destination. The -Path parameter specifies the source files, the -Destination parameter specifies the destination folder, and the -Recurse parameter ensures that files in subdirectories are also copied.

For example, let’s say we have the following files in the “C:\Important” directory:

  • “Report.docx”
  • “Presentation.pptx”
  • “Data\Spreadsheet.xlsx”

After running the PowerShell script, these files will be copied to the “C:\Backups\Backup 2025-30-04” folder, maintaining the original directory structure.

Check out Create Folders with Year, Month, and Day Using PowerShell

Complete PowerShell Script

Now, let’s combine the folder creation and file copying steps into a complete PowerShell script:

$folderName = "Backup " + (Get-Date).ToString("yyyy-MM-dd")
$backupFolder = "C:\Backups\$folderName"

New-Item -ItemType Directory -Path $backupFolder

$sourceFiles = "C:\Important\*"
Copy-Item -Path $sourceFiles -Destination $backupFolder -Recurse

Write-Host "Backup completed successfully. Files copied to $backupFolder"

Here’s a breakdown of the script:

  1. We create the $folderName variable with today’s date and define the $backupFolder variable with the full path.
  2. We use New-Item to create the backup folder with today’s date.
  3. We specify the $sourceFiles variable with the path and pattern of the files to be copied.
  4. We use Copy-Item to copy the files from the source to the backup folder.
  5. Finally, we use Write-Host to display a success message indicating that the backup is completed and provide the path where the files were copied.

When you run this PowerShell script, it will automatically create a folder with today’s date in the “C:\Backups” directory and copy all the files from the “C:\Important” directory into that folder.

You can see the exact output in the screenshot below:

Create a Folder with Todays Date and Copy Files to it using PowerShell

Check out Create Multiple Folders in PowerShell

Schedule the Backup Script

To automate the backup process and run it daily, you can utilize the Windows Task Scheduler. Here’s how you can set it up:

  1. Open the Windows Task Scheduler by searching for it in the Start menu.
  2. Click on “Create Task” in the Actions pane on the right.
  3. Give the task a name and description, such as “Daily Backup”.
  4. In the Triggers tab, click on “New” and set the desired schedule. For example, you can choose “Daily” and specify the time when you want the backup to run.
  5. In the Actions tab, click on “New” and choose “Start a program” as the action type.
  6. In the “Program/script” field, enter the path to the PowerShell executable (e.g., “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”).
  7. In the “Add arguments” field, enter the path to your PowerShell script file (e.g., “-File C:\Scripts\DailyBackup.ps1”).
  8. Click “OK” to save the task.

Now, the backup script will run automatically according to the scheduled time, creating a new folder with the current date and copying the specified files into it.

Conclusion

In this tutorial, we explored how to create a folder with today’s date using PowerShell and copy files into that folder. By using the Get-Date, New-Item, and Copy-Item cmdlets, we can automate the process of creating dated backup folders and copying important files to them.

I hope this tutorial has helped guide you through the process of creating dated folders and copying files using PowerShell.

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.