# Creating a folder named after the current date and time

I'm trying to create a powershell script that creates a new folder with the current date (formatted as yyyy-MM-dd) as a name.

Here's what I have so far:

PS C:\Users\me\Desktop> powershell.exe -command "new-item ($(get-location) + (Get-Date).year + "-" + (Get-Date).month + "-" + (Get-Date).day) -type directo ry" Die Benennung "C:\Users\me\Desktop" wurde nicht als Name eines Cmdlet, ein er Funktion, einer Skriptdatei oder eines ausführbaren Programms erkannt. Überp rüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern ent halten), und wiederholen Sie den Vorgang. Bei Zeile:1 Zeichen:35 + new-item (C:\Users\me\Desktop <<<< + (Get-Date).year + - + (Get-Date). month + - + (Get-Date).day) -type directory + CategoryInfo : ObjectNotFound: (C:\Users\j.moore\Desktop:String ) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException  - ## 2 Answers Try this:  New-Item "$((get-date).toString('yyyy-MM-dd'))" -ItemType directory


or:

md "$((get-date).toString('yyyy-MM-dd'))"  Explanation from this site:$() enables you to use the output of a command in a string

The () around get-date again say "Execute this first" so that we can use the Methods of the DateTime Object returned by get-date

the toString() Method of a DateTime object takes a formattingstring as input.

-
Using an expandable string with a subexpression is more complicated than needed. –  Jay Bazuzi Dec 7 '12 at 16:42
While (Get-Date).ToString(...) works, Get-Date -Format ... is more idiomatic PowerShell. –  Jay Bazuzi Dec 7 '12 at 16:42

Try this:

mkdir (Get-Date -Format "yyyy-MM-dd")

-