Search code examples
powershellcopypowershell-2.0

Powershell 2 copy-item which creates a folder if doesn't exist


$from = "\\something\1 XLS\2010_04_22\*"
$to =  "c:\out\1 XLS\2010_04_22\"
copy-item $from $to -Recurse 

This works if c:\out\1 XLS\2010_04_22\ does exist . Is it possible with a single command to create c:\out\1 XLS\2010_04_22\ if it doesn't exist?


Solution

  • Yes, add the -Force parameter.

    copy-item $from $to -Recurse -Force