如何在PowerShell中远程启动进程 [英] How to start remotely process in PowerShell

查看:350
本文介绍了如何在PowerShell中远程启动进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,我有一个脚本,其中:

I have a problem, I have a script which:

  • 与PSSession连接(我在管理员帐户中使用PSSession)
  • 停止2进程
  • 对文件进行更改
  • 开始2步(问题在这里)
  • Connect with PSSession (I use PSSession with admin account)
  • Stop 2 process
  • Do change on them files
  • Start the 2 process (Problem here)

我想在服务器上启动进程,所以我要连接PSSession(没问题)

I want to start process on server, so i'm connect with PSSession (No problem)

我执行调用命令:

# $pathProg path to my program
Invoke-Command -session $mySession -command {Start-Process $($args[0])} -ArgumentList $pathProg

但是它什么也没做(我已通过VNC验证)

But it does nothing (I verify with VNC)

我也执行Invoke-Command:

I do Invoke-Command too :

# $pathProg path to my program
Invoke-Command -session $mySession -command {&$($args[0])} -ArgumentList $pathProg

它无法执行程序(很好),但是我的脚本等待结束程序(不好)

It lauch the program (Good) but my script wait the end program (Not good)

有人有主意吗?

谢谢

推荐答案

您可以尝试使用WMI:

You can try using WMI:

$command = "notepad.exe"
$process = [WMICLASS]"\\$CompName\ROOT\CIMV2:win32_process"
$result = $process.Create($command) 

如果您需要通过凭据:

$cred = get-credential
$process = get-wmiobject -query "SELECT * FROM Meta_Class WHERE __Class = 'Win32_Process'" -namespace "root\cimv2" -computername $CompName -credential $cred
$results = $process.Create( "notepad.exe" )

这篇关于如何在PowerShell中远程启动进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆