Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Wednesday, July 16, 2014

PowerShell Script to find Process IDs of an Executable

To find the priority of Threads of a process, copy the following script and execute in PowerShell

$timeoutInSeconds = 100;
$processName = "myExecutable.exe"

$processList = Get-WmiObject win32_process | where { $_.ProcessName -eq "$processName" } | select Handle
foreach ($processIds in $processList)
{
    $processId = $processIds.Handle
    Write-Host "process id = $processId"
}


Disclaimer: Use at your own risk. The author does not take any responsibility for the behavior of this script.

Kill Remote Process using PowerShell

Here are the steps to kill a process running on remote machine

1. Start PowerShell
2. $processes = Get-WmiObject -class win32_process -ComputerName <name_of_computer> -Filter "Name='notepad.exe'"
3. $x = $processes.terminate()
4. echo $x

Return value should be 0