10 May,2017 by Tom Collins
Powershell find command and copy a file instructions are required. I need to locate a load of files based on an input file and copy the files to another location.
The requirement is to iterate through the input list – find the file across multiple drives and then copy the file to a destination
Answer: The basis of implementing the Powershell copy is to use the Get-ChildItem cmdlet. Along with the –recurse and filter functionality it’s possible to search recursively through multiple drives based on the filename as the filter.
Using the details found with Get-ChildItem pipe into a Copy-Item cmdlet. Copy-Item copies the file to the destination.
The example below will guide you through the process of reading a list of items and applying the Powershell find process and copy functionality
$servers = "C:\myservers.txt" foreach ($entry in get-content $servers) { $source = "D:\*,E:\*" $destination = "Y:\mydestinationfolder" $filter = $entry Get-Childitem Y:\,R:\ -recurse -filter $filter | Copy-Item -Destination $destination }
If you want to read more about Get-ChildItem read SQL Server - Powershell Get-ChildItem with examples
Explore more Powershell and SQL Server examples in the Powershell Script Library for DBA
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |