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!

Published Tuesday, January 26, 2010 12:22 AM by svdoever
Filed under: ,

Comments

Monday, November 22, 2010 4:26 PM by HarMonica Songs

# re: Debugging executing program from PowerShell using EchoArgs.exe

"I normally don’t publish in Weblogs but your weblog pressured me to, astounding operate..<br> attractive …"

--------------------------------------------

my website is  

http://happykidskaraoke.info

Also welcome you!

Friday, December 03, 2010 5:10 PM by skateboards zero

# re: Debugging executing program from PowerShell using EchoArgs.exe

Blogroll links aint that good :P but i'm not the admin… :P … Just Telling :P

--------------------------------------------

my website is <a href="zeroskateboards.org/.../cool-skateboards-images-10.html">zero skateboarding</a> .Also welcome you!

Sunday, December 05, 2010 7:00 PM by ITalian LAnguage Courses

# re: Debugging executing program from PowerShell using EchoArgs.exe

"Anyway, I guess I am a trifle off topic right here?!!!. Precisely.!!!. It appears like that! Ha, Ha, Ha..."

--------------------------------------------

my website is  

harleydavidsonmotorcyclesblog.com

Also welcome you!

Monday, December 20, 2010 5:03 AM by ipad accessories review

# re: Debugging executing program from PowerShell using EchoArgs.exe

Politeness costs nothing and gains everything.

-----------------------------------

Friday, December 24, 2010 12:20 PM by ipad review wired

# re: Debugging executing program from PowerShell using EchoArgs.exe

Never underestimate your power to change yourself!

-----------------------------------

Monday, January 03, 2011 4:01 PM by ipad app reviews

# re: Debugging executing program from PowerShell using EchoArgs.exe

-----------------------------------------------------------

Hello. Excellent career. I didn't anticipate this over a Wednesday. This is a great narrative. Thanks!

Saturday, January 08, 2011 1:30 PM by ipad stand

# re: Debugging executing program from PowerShell using EchoArgs.exe

-----------------------------------------------------------

"I entirely agree with all the over viewpoint, the world extensive web is certainly without a doubt rising in to the main type of communication round the globe and  it's because of to web sites like this that concepts are spreading so swiftly."

Monday, January 17, 2011 2:13 PM by computer monitor reviews

# re: Debugging executing program from PowerShell using EchoArgs.exe

Wow! what an idea  What an idea Gorgeous  Wonderful …

--------------------------------------------------------------------    

Council on Asian Studies

Thursday, March 31, 2011 1:50 PM by Home Security Monitoring

# re: Debugging executing program from PowerShell using EchoArgs.exe

Great website. Lots of useful info here. I'm sending it to some friends ans also sharing in delicious. And naturally, thanks for your effort!

<b><a href="vegetableguides.net/all-about-home-security

">Home Security Monitoring service

<a/><b/>

Sunday, April 17, 2011 7:06 PM by Cafecancank

# re: Debugging executing program from PowerShell using EchoArgs.exe

windows registry repair

 <a href=www.regtidy.com/>registry repair</a>

registry clean

windows registry cleaner

registry cleanup

i0p0409r

Sunday, April 17, 2011 8:23 PM by tateassupyita

# re: Debugging executing program from PowerShell using EchoArgs.exe

<a href=www.jewelforless.com/pandora-jewelry>best price pandora jewelry</a>

i0p0418j

Wednesday, July 20, 2011 7:12 AM by buy edu backlinks

# re: Debugging executing program from PowerShell using EchoArgs.exe

fantastic submit, very informative. I wonder why the other experts of this sector don't understand this. You should proceed your writing. I am confident, you have a huge readers' base already!  <a href=edubacklinksstore.com/>edu backlinks</a>

Leave a Comment

(required) 
(required) 
(optional)
(required)