INTRODUCTION

If you want to copy a file to a new directory using Powershell, you can’t just run the regular Copy-Item command:

Copy-Item -Path "C:\temp\ccmsetup.log" -Destination "C:\temp\ccmsetup\ccmsetup.log" -Force -Verbose

If you choose this path, you will receive the following error:

SOLUTION

Instead, you need to create the create the folder before copying the file. Use the below one-liner.

Copy-Item -Path "C:\temp\ccmsetup.log" -Destination (New-item -Name "ccmsetup" -Type Folder -Path "c:\temp") -Force -Verbose

RELATED POSTS

USEFUL RESOURCES

BUY POWERSHELL BOOKS ON AMAZON