Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions Links


SQL Server DBA Jobs

Powershell find command and copy a file

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


Author: Tom Collins (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

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.


Post a comment on Powershell find command and copy a file | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer