Create folder with current date as name in powershell
$folderName = (Get-Date).tostring("dd-MM-yyyy-hh-mm-ss")
New-Item -ItemType Directory -Path "E:\parent" -Name $FolderName
It is creating folder with name 11-06-2020-07-29-41 under E:\parent
Yes.
New-Item -ItemType Directory -Path ".\$((Get-Date).ToShortDateString())"
or as alroc suggested in order to get the same formatting no matter the culture.
New-Item -ItemType Directory -Path ".\$((Get-Date).ToString('yyyy-MM-dd'))"
Don't use ToShortDateString()
as @notjustme wrote; its formatting is dependent upon locale and your date format settings in the Regional & Language control panel. For example, on my PC right now, that would produce the following directory name:
C:\Users\me\09\18\2014
Explicitly set the format of the date string instead.
New-Item -ItemType Directory -Path ".\$((Get-Date).ToString('yyyy-MM-dd'))"