简体   繁体   English

如何使用Powershell WMI在远程计算机上启动进程?

[英]How to start a process on remote computer using powershell WMI?

We are upgrading our servers and need to stop our application before we perform update and then start it back again. 我们正在升级服务器,需要先停止应用程序,然后再执行更新,然后重新启动它。

I was reading online about this and most of the links talk about remoting but some of the machines don't have PSRemoting enabled and therefore I need to stick to using wmi . 我正在网上阅读有关此内容的信息,大多数链接都谈到了remoting但是某些机器未启用PSRemoting ,因此我需要坚持使用wmi

Would appreciate some pointers on this ? 希望对此提出一些建议吗?

To terminate the process I am using something like below: 要终止该过程,我将使用以下方法:

$processes=Get-WmiObject -Class Win32_Process -ComputerName $Address -Filter "name='$ProcessName'"

foreach ($process in $processes) 
{
    $returnval = $process.terminate()
    $processid = $process.handle

    if($returnval.returnvalue -eq 0) {
        write-host "The process $ProcessName `($processid`) terminated successfully"
    }
    else {
        write-host "The process $ProcessName `($processid`) termination has some problems"
    }
}

You don't say what OS and PS version(s) you are trying to deal with. 您没有说您要处理的OS和PS版本。

You are not saying what or if you are having issues with what you posted. 您不是在说什么,还是在发布内容时遇到问题。

Even using only WMI, you still must have Windows WMI properly configured to do this as well as know Windows is not out of the boxed configured to let you what you are after without making all the proper WinRM, WMI and firewall manual configs. 即使仅使用WMI,您仍然必须正确配置Windows WMI才能执行此操作,并且要知道Windows没有开箱即用的配置,可以在不进行所有正确的WinRM,WMI和防火墙手动配置的情况下为您提供所需的信息。

It's far simpler just to enable PSRemoting via GPO. 仅通过GPO启用PSRemoting更加简单。

Otherwise, you will need tp look toward maybe winrs.exe or MS SysInternals psexec. 否则,您将需要对twin看看winrs.exe或MS SysInternals psexec。

winrs Windows remote Management allows you to manage and execute programs remotely. winrs Windows远程管理使您可以远程管理和执行程序。

PsExec v2.2 PsExec v2.2

Also back to my what OS and PowerShell version you are using. 还要回到我正在使用的OS和PowerShell版本。 There is the

Invoke-Wmi​Method 调用Wmi方法

Which can lead to stuff like this --- 会导致这样的事情-

Invoke-WmiMethod -ComputerName $TargetMachine -Namespace root\cimv2 -Class Win32_Process..."

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM