使用PowerShell的Invoke-Command加载.exe但exe不读取.config文件

时间:2017-09-21 21:27:04

标签: powershell

我目前正在使用以下命令运行exe。 .exe运行正常,但是,它不会读取与程序关联的配置文件。我使用了这个solution并且它有效。但是,我想添加类似“-WorkingDirectory”的内容,但使用invoke-command。我的最终目标是能够使用此脚本运行exe作为tfs构建的一部分。

$file = 'C:\test.exe'
Invoke-Command -ScriptBlock { Param($myarg) & $file }

1 个答案:

答案 0 :(得分:0)

将目录作为参数传递,并使用Set-Location更改scriptblock中的工作目录:

$file = 'C:\test.exe'
Invoke-Command -ScriptBlock {
    Param($exe, $wd)
    Set-Location $wd
    & $exe
} -ArgumentList $file, 'C:\working\directory'

话虽如此,使用Invoke-Command是没有意义的,除非您想在不同的计算机上运行某些东西,使用不同的凭据,或作为后台作业(或上述任何组合)。否则你也可以改变目录并直接运行命令:

Set-Location 'C:\working\directory'
& $file