INTRODUCTION

Sometimes you will need to copy a file from one location to a new location which does not yet exist.

This blog post describes how to accomplish this.

SOLUTION

Here is a small Powershell script for copying a file from one destination to another. In this example, a file will be copied from a server to a local directory.

$targetdirectory = "D:\To" 
$sourcedirectory = "\server\from"
if (-not(Test-Path -path $targetdirectory)) {
New-Item $targetdirectory -Type Directory}
Copy-Item -Path $sourcedirectory\file.zip -Destination $targetdirectory
}

RELATED POSTS