≡ Menu

Create a folder/file with today’s date and time using PowerShell

I have seen few people asking for a way to create folder or file with today’s date and time in name using powershell. Though it is easy, many people ask for this. Given the demand, I am authoring this quick post.

Create folder using todays date and time:

$folderName = (Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")            
New-Item -itemType Directory -Path c:\scripts -Name $FolderName

Executing the above code will create a folder with current date and time in c:\scripts folder. You can choose to adjust the format of date time in the above code.

Create file using todays date and time:

$FileName = (Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")            
New-Item -itemType Directory -Path c:\scripts -Name ($FileName + ".log")

Hope this tips helps you.

{ 6 comments… add one }
  • Mohammed May 15, 2013, 2:20 am

    New-Item -itemType will be ‘File’, not ‘Directory’.

    $FileName = (Get-Date).tostring(“dd-MM-yyyy-hh-mm-ss”)
    New-Item -itemType File -Path c:\scripts -Name ($FileName + “.log”)

    Also convenient format is “yyyyMMdd-hhmmss”. Sorting works better with this format.


  • dheeraj May 15, 2015, 5:18 pm

    it worked for me , thank you

  • Dhinesh July 15, 2019, 11:55 pm

    Thanks its worked to get file name created with date and time

  • subramanien July 30, 2019, 3:55 am

    I want to create 3 folders,
    1: for current month,
    2: current date
    3: want to save the output Report/ logs into the current date folder

    if the folders are exists should not through any error. Thanks in Advance

Leave a Comment