Skip to main content
TopMiniSite

Back to all posts

How to Make A Filename By Date With Powershell?

Published on
3 min read
How to Make A Filename By Date With Powershell? image

Best Powershell Script Guides to Buy in November 2025

1 PowerShell Pocket Reference: Portable Help for PowerShell Scripters

PowerShell Pocket Reference: Portable Help for PowerShell Scripters

BUY & SAVE
$18.99 $29.99
Save 37%
PowerShell Pocket Reference: Portable Help for PowerShell Scripters
2 Powershell for Beginners A Step-by-Step Guide to Learning Scripting, Cmdlets: Learn PowerShell Basics, Automate IT Tasks, and Boost Productivity with Clear Examples and Practical Exercises

Powershell for Beginners A Step-by-Step Guide to Learning Scripting, Cmdlets: Learn PowerShell Basics, Automate IT Tasks, and Boost Productivity with Clear Examples and Practical Exercises

BUY & SAVE
$24.99
Powershell for Beginners A Step-by-Step Guide to Learning Scripting, Cmdlets: Learn PowerShell Basics, Automate IT Tasks, and Boost Productivity with Clear Examples and Practical Exercises
3 PowerShell Cookbook: Your Complete Guide to Scripting the Ubiquitous Object-Based Shell

PowerShell Cookbook: Your Complete Guide to Scripting the Ubiquitous Object-Based Shell

BUY & SAVE
$49.49 $89.99
Save 45%
PowerShell Cookbook: Your Complete Guide to Scripting the Ubiquitous Object-Based Shell
4 Beginner’s Guide to PowerShell Scripting: Automate Windows Administration, Master Active Directory, and Unlock Cloud DevOps with Real-World Scripts and Projects

Beginner’s Guide to PowerShell Scripting: Automate Windows Administration, Master Active Directory, and Unlock Cloud DevOps with Real-World Scripts and Projects

BUY & SAVE
$0.99
Beginner’s Guide to PowerShell Scripting: Automate Windows Administration, Master Active Directory, and Unlock Cloud DevOps with Real-World Scripts and Projects
5 PowerShell for Beginners: A Step-by-Step Guide to Scripting Success

PowerShell for Beginners: A Step-by-Step Guide to Scripting Success

BUY & SAVE
$9.99
PowerShell for Beginners: A Step-by-Step Guide to Scripting Success
6 Learn Windows PowerShell in a Month of Lunches

Learn Windows PowerShell in a Month of Lunches

BUY & SAVE
$34.99
Learn Windows PowerShell in a Month of Lunches
7 Windows PowerShell in Action

Windows PowerShell in Action

  • BRAND NEW AND FACTORY-SEALED FOR ULTIMATE FRESHNESS.
  • COMES WITH ALL ESSENTIAL ACCESSORIES INCLUDED.
  • FAST SHIPPING ENSURES QUICK DELIVERY TO YOUR DOORSTEP!
BUY & SAVE
$59.99
Windows PowerShell in Action
8 PowerShell in Depth

PowerShell in Depth

BUY & SAVE
$59.99
PowerShell in Depth
9 PowerShell 7 for IT Professionals

PowerShell 7 for IT Professionals

BUY & SAVE
$27.12 $50.00
Save 46%
PowerShell 7 for IT Professionals
+
ONE MORE?

To create a filename using the current date in PowerShell, you can use the Get-Date cmdlet to generate the date and format it using the -Format parameter. You can then concatenate this formatted date with a string to create the desired filename. Here is an example of how you can do this:

$today = Get-Date -Format "yyyy-MM-dd" $filename = "output_$today.txt"

In this example, the variable $today stores the current date in the format "yyyy-MM-dd". You can adjust the format string to specify a different date format if needed. The variable $filename then concatenates the formatted date with the string "output_" and the file extension ".txt" to create the final filename.

How to add the day of the week to a filename using Powershell?

You can add the day of the week to a filename in Powershell by using the Get-Date cmdlet to get the current date and then using the ToString method to format the date in the desired way. Here's an example script that adds the day of the week to a filename:

# Get current date $date = Get-Date

Format date to include day of the week

$dayOfWeek = $date.ToString("dddd")

Define original filename

$originalFilename = "example.txt"

Create new filename with day of the week

$newFilename = "$dayOfWeek-$originalFilename"

Rename file

Rename-Item -Path $originalFilename -NewName $newFilename

This script will get the current date, extract the day of the week, and then append it to the original filename to create a new filename. Finally, it renames the file with the new filename.

How to create a directory structure based on the date in Powershell?

To create a directory structure based on the date in Powershell, you can use the following script:

# Get the current date $date = Get-Date

Create the directory path based on the date

$path = "C:\RootDirectory\" + $date.Year + "\" + $date.ToString("MM-dd-yyyy")

Create the directory if it does not exist

if (-not (Test-Path $path)) { New-Item -Path $path -ItemType Directory Write-Host "Directory created: $path" } else { Write-Host "Directory already exists: $path" }

This script will create a directory structure under C:\RootDirectory\ with the year as the first level directory, and the date formatted as "MM-dd-yyyy" as the second level directory. It first gets the current date using Get-Date, then constructs the directory path based on the date. It then checks if the directory already exists using Test-Path, and if it does not exist, it creates the directory using New-Item.

You can customize the directory path and date format to suit your specific requirements.

How to format the date in a filename using Powershell?

You can format the date in a filename using Powershell by using the Get-Date cmdlet to retrieve the current date/time and then using the -f operator to format the date according to your requirements. Here is an example of how you can format the date in a filename:

# Get the current date/time $date = Get-Date

Format the date in "yyyyMMdd" format

$dateFormatted = $date.ToString("yyyyMMdd")

Create a filename with the formatted date

$filename = "example_" + $dateFormatted + ".txt"

Output the filename

Write-Output $filename

This script will output a filename in the format "example_YYYYMMDD.txt", where YYYY is the year, MM is the month, and DD is the day. You can adjust the format string in the ToString method to customize the date format according to your preference.