Search code examples
powershellpsake

How to debug/diagnose cause of Powershell Copy-Item command failing in psake script?


I have a very simple script that uses Copy-Item in the Task Build section following the psake conventions (and examples). Right now that's all it does in an attempt to simplify the script to debug this issue.

The Error:

18/07/2011 5:40:57 PM: An Error Occurred:

Exec: Error executing command: Copy-Item "$src_dir..\somefolder*.dll" $bin_dir

I have tried just outputting the file paths via Write-Host and they look fine.

I need some help please debugging this, getting the script code (Copy-Item) to work in isolation to psake isn't an objective.

The Script:

Properties {
    $src_dir = Split-Path $psake.build_script_file
    $bin_dir= "$build_dir\..\Binaries\"
}

include .\psake_ext.ps1

Task Build -Depends Clean, Init {
    Write-Host "about to error here:"

    Exec { Copy-Item "$src_dir\..\somefolder\*.dll" $bin_dir }

    Write-Host "do NOT get this far"
    #more similar Exec copy commands, that don't execute
}

Task Clean {    

}

Also note:

This script was working and only intermittently failing in the very recent past, but now seems to fail more consistently.

Executed via:

.\psake.ps1 "failing-copy-script.ps1" Build

Solution

  • So this question has an answer, summarizing the comments from question and other info:

    If you are experiencing this issue diagnostic steps to take:

    1. "Have you tried turning it off and on again?" - Close anything that may have to do with the script, including your IDE, even restart your machine.
    2. Try a tool like lockhunter
    3. Avoid using 'Exec { bla }' command if it is not required.
    4. Search for hooks with Process Explorer