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 October 2025

1 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
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 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
4 PowerShell Cookbook for Beginners: A Fat-Free Guide to PowerShell Commands (Fat Free PowerShell Guides)

PowerShell Cookbook for Beginners: A Fat-Free Guide to PowerShell Commands (Fat Free PowerShell Guides)

BUY & SAVE
$25.99
PowerShell Cookbook for Beginners: A Fat-Free Guide to PowerShell Commands (Fat Free PowerShell Guides)
5 Mastering PowerShell Scripting: Automate repetitive tasks and simplify complex administrative tasks using PowerShell

Mastering PowerShell Scripting: Automate repetitive tasks and simplify complex administrative tasks using PowerShell

BUY & SAVE
$26.62 $49.99
Save 47%
Mastering PowerShell Scripting: Automate repetitive tasks and simplify complex administrative tasks using PowerShell
6 Windows Server 2022 & PowerShell All-in-One For Dummies (For Dummies (Computer/Tech))

Windows Server 2022 & PowerShell All-in-One For Dummies (For Dummies (Computer/Tech))

BUY & SAVE
$49.99
Windows Server 2022 & PowerShell All-in-One For Dummies (For Dummies (Computer/Tech))
7 PowerShell 7 for IT Professionals

PowerShell 7 for IT Professionals

BUY & SAVE
$27.12 $50.00
Save 46%
PowerShell 7 for IT Professionals
8 Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

  • QUALITY ASSURANCE: CAREFULLY INSPECTED FOR GOOD CONDITION.
  • AFFORDABLE PRICES: GREAT SAVINGS ON QUALITY USED BOOKS.
  • ECO-FRIENDLY CHOICE: SUPPORT RECYCLING BY BUYING USED!
BUY & SAVE
$69.80
Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell
9 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
+
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.