Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
share|improve this question
up vote 3 down vote accepted

Try this:

 New-Item "$((get-date).toString('yyyy-MM-dd'))" -ItemType directory


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.

share|improve this answer
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")
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .