使用splatting启动进程和powershell.exe

使用splatting启动进程和powershell.exe,powershell,Powershell,我已经尝试了几天,现在多线程的WPF图形用户界面将运行一个PS3.0脚本一旦按钮被点击。我不能使用start job,因为我必须跟踪(一次跟踪多个会话),但是,我只想在单独的PS进程中运行脚本,就像从快捷方式打开脚本的多个实例一样。并且能够有一个打开的PS窗口来跟踪脚本本身的进度 预期结果是在powershell.exe会话中启动脚本并传递3个参数-2个字符串和1个布尔值。由用户提供 因此,在ISE中: C:\temp\test.ps1 -argumentlist $computername $

我已经尝试了几天,现在多线程的WPF图形用户界面将运行一个PS3.0脚本一旦按钮被点击。我不能使用start job,因为我必须跟踪(一次跟踪多个会话),但是,我只想在单独的PS进程中运行脚本,就像从快捷方式打开脚本的多个实例一样。并且能够有一个打开的PS窗口来跟踪脚本本身的进度

预期结果是在powershell.exe会话中启动脚本并传递3个参数-2个字符串和1个布尔值。由用户提供

因此,在ISE中:

C:\temp\test.ps1 -argumentlist $computername $username $citrixtest
很好。 我花了几个小时在互联网上搜索,只找到了一个推荐开始工作的线程,或者一个使用后台工作人员的方法——这不是我想要从脚本中得到的

所以我猜通过点击按钮进行的调用类似于(我尝试过的一些事情)

不将参数传递给test.ps1-但是,它正在进入“暂停”-因此脚本成功启动

test.ps1在哪里

$ComputerName 
$UserName 
$CitrixTest 
pause
来电者:

function Caller {
Param (
    $ScriptPath = "c:\temp\test.ps1"
)

$Arguments = @()
$Arguments += "-computername $ComputerName"
$Arguments += "-UserName $UserName"
$Arguments += "-citrixtest $citrixtest"
$StartParams = @{   
    ArgumentList = "-File ""$ScriptPath""" + $Arguments
}
    Start-Process powershell @StartParams
}
Caller
不完全启动脚本-PS窗口刚刚关闭-可能找不到.ps1脚本的路径

还有一种不同的方法,它也在脚本中启动,但不传递参数

$scriptFile = '"C:\temp\test.ps1"'
[string[]]$argumentList = "-file"
$argumentList +=  $scriptFile
$argumentlist += $computername
$argumentlist += $UserName
$argumentlist += $CitrixTest

$start_Process_info =  New-Object System.Diagnostics.ProcessStartInfo
$start_Process_info.FileName = "$PSHOME\PowerShell.exe"
$start_Process_info.Arguments = $argumentList


$newProcess = New-Object System.Diagnostics.Process
$newProcess.StartInfo = $start_Process_info

$newProcess.Start() | Out-Null

有没有办法让这一切按我的意愿进行?或者我应该更深入地挖掘运行空间并尝试使用它吗?

@Bill\u Stewart我刚刚意识到我没有在脚本中添加参数(args)。。。 这就是为什么它不会像我希望的那样提取这些变量。当我回到办公室的时候,我必须检查一下,这是否就是我错过的

在我的运行PS 5.1的笔记本电脑上进行了检查,这似乎按照预期工作

$testarg = @(
    '-File'
    "C:\temp\test.ps1"
    "$computername"
    "$username"
    "$citrixtest"
)

Start-Process powershell.exe -ArgumentList $testarg
其中test.ps1为:

param(
$ComputerName,
$UserName,
$citrixtest
)

$ComputerName 
$UserName 
$CitrixTest 
pause

所以故障
启动过程是否不起作用?请用出错/错误消息更新问题?或者是
Click()
处理程序有问题(即执行基本的
写主机“Hello World”
测试)?还可以尝试一个基本的
Click()
处理程序测试,输出变量。很可能没有将变量设置/传递给
Click()
处理程序来启动
启动流程
没有任何与单击相关的内容,只是它最终会调用它。我需要作为单独的powershell.exe会话运行:C:\temp\test.ps1-argumentlist$computername$username$Citrix测试。不使用启动作业。第一个脚本根本不向测试传递参数。ps1脚本第二个脚本似乎不工作(完全启动和关闭-很可能找不到路径)第三个脚本根本不向测试传递参数。ps1脚本您的脚本有一个名为
-argumentlist
param(
$ComputerName,
$UserName,
$citrixtest
)

$ComputerName 
$UserName 
$CitrixTest 
pause