我想以"test"用户的身份在远程服务器上启动一个进程,但它不起作用,我找不到原因。
$PW = convertto-securestring -AsPlainText -Force -String 'XXXX'
$CRED = new-object -typename System.Management.Automation.PSCredential -argumentlist "domaintest", $PW
$Server = new-pssession -computername ServerName -credential $CRED
Invoke-Command -session $Server -ScriptBlock {
$APP = "C:testapp.exe"
if ((Get-Process -Name app -ErrorAction SilentlyContinue) -eq $null) {
write-host "not running"
Start-Process -FilePath $APP
}
else {
write-host "running"
}
}
Remove-PSSession $Server
如果我通过RDP进入远程服务器并直接运行代码,它将启动应用程序,但是如果我使用Invoke-Command
通过我的机器运行代码,它不会启动任何内容。
我试图通过RDP查看远程服务器上发生的过程,但没有任何反应。此应用程序必须在我在脚本和 RDP 会话中使用的特定用户"测试"下运行。
远程服务器为Win2012R2,PS版本为4.0
我机器上的 PS版本是 5.1
不能使用远程处理启动交互式应用程序。
经过所有类型的测试,看起来没有办法通过 PSrmoting 启动此应用程序。
我的解决方案是
1( 使用PSTools中的"自动登录.exe"在重新启动后以所需用户身份登录。
2( 计划在用户登录任务计划程序时运行此应用程序。
效果很好.