Copy file(s) from one location to another using Power Shell script   Leave a comment

Below is the code to copy the file(s) from one location to another by reading the file name(s) from the text file.

$SourcePath = 'D:\Source\'
$DestinationPath = 'D:\Destination\'
foreach ($Trans in get-content D:\FileList.txt) {
        $fileNames  = Get-ChildItem -Recurse -Force $filePath -ErrorAction SilentlyContinue | Where-Object { ( $_.Name -like "*$fileName*") }

        foreach ($F in $fileNames){
                $fileName = $F.Name
                $fullpath = $SourcePath + $fileName
                Copy-Item -Path $fullpath  -Destination $DestinationPath
        }
}
Advertisements

Posted September 26, 2014 by Izharuddin Shaikh in Power Shell

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: