Running TFS commands with arguments in powershell

2.9k views Asked by At

Hi I am trying to run the "tf get" command through powershell but i always get a unexpected token error when it reaches the arugments.

I was following the instructions from this post TFS commands in PowerShell script

the line where the error is happening is

"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe" @("get", $args[$i])

where $args[$i] is an argument being entered by the user, but the script stops executing after calling the tf.exe

Could someone help me out here? Thanks.

1

There are 1 answers

0
Keith Hill On BEST ANSWER

You can't execute a command in a string without using the call operator e.g. &. In PowerShell a string evaluates to a string e.g.:

C:\> "hello world"
hello world

You have to tell PowerShell that the string contains the name of a command using the call operator.

$tf = 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe'
& $tf get $args[$i]

Note: when using & the string must contain just the name of the command. Arguments should be specified separately.