Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
5.5k views
in PowerShell by 37 41 48

In PowerShell, How I can create a new folder with the current date and time as a name in a specific path

For example:

I need to create folder in PowerShell with date name like "Backup CurrentDate CurrentTime" (Backup 2020-11-08-11-30-pm) in the C:\ Drive or specific location.


1 Answer

0 like 0 dislike
by 163 206 413
selected by
 
Best answer

How to Create a folder in PowerShell?

To create a folder in a specific path in PowerShell, you should use the below cmdlet:

$path = "c:\backup"
New-Item -ItemType Directory -Path $path
start $path

How to create a folder with date as a name in PowerShell?

To create a folder in a specific path with the current date and time as a name in PowerShell, you should use the below cmdlet:

$path = "c:\backup $((Get-Date).ToString('yyyy-MM-dd hh-mm-ss-tt'))"
New-Item -ItemType Directory -Path $path
start $path

Output

PowerShell create a folder with date as a name


See Also

If you don’t ask, the answer is always NO!
...