Powershell Create a New Directory Named With Todays Date

powershell

Powershell Create a New Directory Named With Todays Date

This is a common requirement if using powershell to run certain scripts on a schedule and have the output stored in a dated folder e.g. a backup script. This solution is a pretty straight forward way of creating the directory.

$today = (Get-Date -Format dd-MM-yyyy)
$path = "\\server\share\" + "$Today"
new-item -path $path -itemtype directory

I found if I tried to type the path for the new-item cmdlet with $today on the end it simply created a directory named $today but the extra line to create $path gets the desired result.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>