Archives

Archives / 2010 / January
  • Debugging executing program from PowerShell using EchoArgs.exe

    Sometimes you pull you hairs out because the execution of a command just does not seem to work the way you want from PowerShell.

    A good example of this is the following case:

    Given a folder on the filesystem, I want to determine if the folder is under TFS source control, and if it is, what is the server name of the TFS server and the path of folder in TFS.

    If you don’t use integrated security (some development machines are not domain joined) you can determine this using the command tf.exe workfold c:\projects\myproject /login:domain\username,password

    From PowerShell I execute this command as follows:

    $tfExe = "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Tf.exe"
    $projectFolder = "D:\Projects\Macaw.SolutionsFactory\TEST\Macaw.TestTfs"
    $username = "domain\username"
    $password = "password"
    & $tfExe workfold $projectFolder /login:$username,$password

    But I got the the following error:

    TF10125: The path 'D:\Projects\MyProject' must start with $/

    I just couldn’t get it working, so I created a small batch file ExecTfWorkprodCommand.bat with the following content:

    @echo off
    rem This is a kind of strange batch file, needed because execution of this command in PowerShell gives an error.
    rem This script retrieves TFS sourcecontrol information about a local folder using the following command:
    rem tf workfold <localpath> /login:domain\user,password
    rem %1 is path to the tf.exe executable
    rem %2 is the local path
    rem %3 is the domain\user
    rem %4 is the password
    rem Output is in format:
    rem ===============================================================================
    rem Workspace:
    MyProject@VS-D-SVDOMOSS-1 (Serge)
    rem Server   : tfs.yourcompany.nl
    rem $/MyProject/trunk: C:\Projects\MyProject

    if [%3]==[] goto integratedsecurity
    %1 workfold "%2" /login:%3,%4
    goto end

    :integratedsecurity
    %1 workfold "%2"

    :end

    And called this script file from PowerShell as follows:

    $helperScript = "ExecTfWorkprodCommand.bat"
    $tfExe = "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Tf.exe"
    $projectFolder = "D:\Projects\Macaw.SolutionsFactory\TEST\Macaw.TestTfs"
    $username = "domain\username"
    $password = "password"
    $helperScript $tfExe "`"$projectFolder`"" $username $password

    This is way to much work, but I just couldn’t get it working.

    Today I read a post that mentioned the tool EchoArgs.exe, available in the PowerShell Community Extensions (http://pscx.codeplex.com), which echo’s the arguments as the executed application receives them from PowerShell.

    I changed my script code to:

    $tfExe = "C:\Program Files\PowerShell Community Extensions\EchoArgs.exe"
    $projectFolder = "D:\Projects\MyProject"
    $username = "domain\username"
    $password = "password"
    & $tfExe workfold $projectFolder /login:$username,$password

    Which resulted in:

    Arg 0 is <workfold>
    Arg 1 is <D:\Projects\MyProject>
    Arg 2 is </login:domain\username>
    Arg 3 is <password>

    And this directly resolved my issue! the “,” in “/login:$username,$password” did split the argument!

    The issue was simple resolved by using the following command from PowerShell:

    & $tfExe workfold $projectFolder /login:"$username,$password"

    Which results in:

    Arg 0 is <workfold>
    Arg 1 is <D:\Projects\MyProject>
    Arg 2 is </login:domain\username,password>

    Conclusion: issues with executing programs from PowerShell, check out EchoArgs.exe!