0

I have a script that is finding a few files and the copying them. This is part of a psake build script.

The command is:

Get-ChildItem -Path "$sourceFolder" -Include "*.ispac" -Recurse `
    | Select-Object -ExpandProperty FullName `
    | Copy-Item -Destination "$caseFolder\" -Force -Verbose

When I execute this, I get this for the message:

VERBOSE: Performing the operation "Copy File" on target 
"Item: C:\Source\TestSssisOne.ispac 
Destination: C:\Destination\TestSssisOne.ispac".

That sure looks like the files where copied. But they aren't. No errors. If I copy this command out to ISE and setup the variables, it copies no problem. I tried to just manually copy a single file, with explicit paths. Again, in script it does not copy, but in PS console or ISE it does.

I have no idea what could be the problem. I've used Copy-Item in psake scripts. In fact, I copied the above code to a later task and it works! In the task where it isn't working I'm calling msbuild to build a solution.

Any insight appreciated!

Greg McGuffey
  • 3,116
  • 3
  • 38
  • 58
  • First things that come to mind are: Permissions. Masking or throwing away error messages. Deleting the files somewhere else after being copied... From what you've posted, that's all I could think of. If you have full access to the server executing the script, my first actions would be to get a procmon trace and look for errors. If that doesn't solve it, setting PSDebug in script and try to narrow it down. – Lieven Keersmaekers Oct 13 '16 at 05:11

1 Answers1

1

modify your code like this

 Get-ChildItem -Path "$sourceFolder" -Include "*.ispac" -Recurse -File | foreach{Copy-Item $_.FullName -Destination (("$caseFolder\") + $_.Name)   -Force -Verbose }
Esperento57
  • 16,521
  • 3
  • 39
  • 45