Monday, August 9, 2010

Copy-Items, Loops and Variables

Needed to copy 310,000 files scattered all over an old archive. I know how to do loops, I know how to use COPY-ITEM cmdlet, and I know Variables. Now do I know that I can use them together? Yes you can. I built this from scratch hoping it would work and it does.

$list = Get-Content "'Location of list'\list.txt"
Foreach ($file in $list)
{
Copy-Item "Location of Original Files"
\$file C:\"Destination Location"
}


Very simple. Make a list of the files you have to grab and call it $LIST

Enter the loop where each $FILE equals a file name in the $LIST

Copy each $FILE from it original location to the destination.

Done and Done.

-Boston Tech Guy out