0

The below script doesn't error out and it doesn't work. I have trapped it inside of a try catch block and that isn't working either. I am attempting to move only pdb, and dll files to a certain folder. However, when I run this script, the dll's and pdb's aren't moved. I probably have an order of operations mixup or something, but I thought this script should have worked...

gci -path $FromPath -Include ("*.dll", "*.pdp") | ? {$_.Name -match "PackageServiceLib|Package.capture.CSE.inc|PackageDBCore|Package.capture|PackageCommon|PackageServiceFramework"} | Copy-item -path $FromPath -destination $ToPath -force 
SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195
  • 1
    Any time you're dealing with a complex issue like this, scale things back and build it one step at a time. Start with the `Get-ChildItem` command, and make sure it's returning the data you're expecting, then move onto the `Where-Object` filter, and so on. –  Jan 15 '14 at 17:58
  • Good point. I thought I broke down everything pretty well. Obviously though I missed something. – SoftwareSavant Jan 15 '14 at 18:05

1 Answers1

1

My guess is that your $FromPath variable doesn't specify \* at the end. If you don't specify that, then your -Include parameter will be useless.

Assuming that a folder named c:\test contains 10 files with a .txt file extension, consider the difference between this:

Get-ChildItem -Path c:\test -Include *.txt;

And this:

Get-ChildItem -Path c:\test\* -Include *.txt;

The first command will yield no output, because you are getting the directory, not the children of the directory. In the second command, we are specifying that we want everything that is a child of the directory, except we only want the items that match the -Include parameter.