Search code examples
powershellpsake

Copy-Item is not working


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!


Solution

  • modify your code like this

     Get-ChildItem -Path "$sourceFolder" -Include "*.ispac" -Recurse -File | foreach{Copy-Item $_.FullName -Destination (("$caseFolder\") + $_.Name)   -Force -Verbose }