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 File -Path c:\scripts -Name ($FileName + ".log")
Hope this tips helps you.