Display the Parent Process of given Process

Supply the process name as parameter to display its parent process name.

Script

<#
.SYNOPSIS
This script can be used to display parent process name of a process.
.DESCRIPTION
This script can be used to display parent process name of a process.
.EXAMPLE
C:\PS> C:\Script\Parent_Process.ps1 taskhost.
Displays the parent process name of taskhost.
#>

Param([String] $program)
$process = Get-Process -Name $program
#get the process id of the given process

$id = $process.Id
#Obtain The parent process id.

$instance = Get-WmiObject Win32_Process -Filter “ProcessId = ‘$id'”
$instance.ParentProcessId
#Fetch the process with the parentprocess id.

$parentProcess = Get-Process -Id $instance.ParentProcessId
$parentProcess

 

Output
Parent

Leave a Reply