在powershell中使用参数运行TFS命令

use*_*901 2 powershell tfs tf-cli

嗨,我试图通过powershell运行"tf get"命令但是当它到达arugments时我总是遇到意外的令牌错误.

在PowerShell脚本中遵循此帖后TFS命令的说明

发生错误的行是

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

其中$ args [$ i]是用户输入的参数,但脚本在调用tf.exe后停止执行

有人可以帮帮我吗?谢谢.

Kei*_*ill 5

如果不使用调用操作符,则无法在字符串中执行命令&.在PowerShell中,字符串求值为字符串,例如:

C:\> "hello world"
hello world
Run Code Online (Sandbox Code Playgroud)

您必须告诉PowerShell该字符串包含使用call运算符的命令名称.

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

注意:使用&字符串时必须只包含命令的名称.参数应单独指定.