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

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

#copy-file-using-power-shell