Thursday, December 13, 2012

Copy file(s) from one location to another...in POWERSHELL

What's it do?
  • Copies specific files from one directory to another



# source and destionation directory
$src_dir = "E:\Yourstuff"
$dst_dir = "C:\Mystuff"

# list of files from source directory that I want to copy to destination folder
# unconditionally
$file_list = "finals.ppt",

"term-paper.doc",
"schedule.xls",
"drafts.doc"

# Copy each file unconditionally (regardless of whether or not the file is there
foreach ($file in $file_list)
{
  Copy-Item $src_dir$file $dst_dir
}



First do this:
  • Make sure you Run-as admin
  • Type Set-ExecutionPolicy unrestricted
  • Run the script

No comments:

Post a Comment