Create folder with current date as name in powershell Create folder with current date as name in powershell powershell powershell

Create folder with current date as name in powershell


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'))"


The shorter way is

$date = get-date -Format yyyy-MM-dd