简体   繁体   中英

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 .

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.

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.

It's far simpler just to enable PSRemoting via GPO.

Otherwise, you will need tp look toward maybe winrs.exe or MS SysInternals psexec.

winrs Windows remote Management allows you to manage and execute programs remotely.

PsExec v2.2

Also back to my what OS and PowerShell version you are using. There is the

Invoke-Wmi​Method

Which can lead to stuff like this ---

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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