Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Copying files from folder with a filter.

$
0
0

Hey Guys,

I've got a folder on a share with files in it. I need to copy files with certain extensions, to a set of remote folders. I've got the routine to copy to multiple shared, but the problem that I'm running into is that when I get the files I want to copy, it tries to copy them from the working dir vs the actual path.

Here is what I'm using to take in the files:

$ExeDatLstSource = Get-ChildItem "\\server1\D$\folder" -Force | Where-Object {($_.Extension -eq ".exe") -or ($_.Extension -eq ".dat") -or ($_.Extension -eq ".lst")}

And then I have:

foreach ($item in $Servers) 
{Copy-Item $ExeDatLstSource -Destination \\$item\C$\WINDOWS\CSLIBRARY -Force -whatif}

It then tries to copy each filename it found in the $ExeDatLstSource but from the Current Working dir, not the Dir that they are actually in (\\server1\D$\folder).

What do I need to change to have it get the actual files, not just the filenames.


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>