通过传递本地参数远程从共享位置调用.ps1

时间:2017-03-09 18:49:28

标签: powershell remote-server unc

我有一组10个VM,我必须在其上执行一些测试。用户将能够从任何本地m / c或VM触发驱动器脚本(1.ps1)。有一个数据集,测试DLL和一个放在共享驱动器上的附加脚本(2.ps1)。 2.ps1接受本地参数。我想通过传递参数从1.ps1调用2.ps1。 执行策略不受限制,映射UNC路径。远程启用。

我尝试过以下操作,但没有成功:

$ scriptPath =' \\ $ ip2 \ path \ 2.ps1'

#1
Invoke-Command -computername $ip -ScriptBlock{$scriptPath -PARAM $param} -Credentials $cred

#2
Invoke-Command -computername $ip -ScriptBlock{param($param) $scriptPath -PARAM $param} -ArgumentList $param -Credentials $cred

#3
Invoke-Command -computername $ip -ScriptBlock{$using:scriptPath -PARAM $using:param} -Credentials $cred

2.ps1的内容:

param (
    [string]$RUNSETTINGS,
    [string]$VERSION
    #[string]$COMPUTER
)
$env:TEST_HOME = "\\$ip\FMLTestBed\MasterData"
$testDLL = Join-Path $env:TEST_HOME "Test.dll"

$verFolder = "TEST_" + $VERSION
$SettingFile = Join-Path (Join-Path (Join-Path $env:TEST_HOME "TestsInput") $verFolder) "test.runsettings"

$vstestPath = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
&$vstestPath $testDLL /Settings:"$SettingFile"

有人可以用正确的方法帮助我吗?

0 个答案:

没有答案