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 -RecurseIn 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:
- We create the
$folderNamevariable with today’s date and define the$backupFoldervariable with the full path. - We use
New-Itemto create the backup folder with today’s date. - We specify the
$sourceFilesvariable with the path and pattern of the files to be copied. - We use
Copy-Itemto copy the files from the source to the backup folder. - Finally, we use
Write-Hostto 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:

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:
- Open the Windows Task Scheduler by searching for it in the Start menu.
- Click on “Create Task” in the Actions pane on the right.
- Give the task a name and description, such as “Daily Backup”.
- 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.
- In the Actions tab, click on “New” and choose “Start a program” as the action type.
- In the “Program/script” field, enter the path to the PowerShell executable (e.g., “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”).
- In the “Add arguments” field, enter the path to your PowerShell script file (e.g., “-File C:\Scripts\DailyBackup.ps1”).
- 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:
- Set Folder Permissions Using PowerShell
- Find and Remove Empty Folders Using PowerShell
- Rename a Folder in PowerShell if It Exists
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.