How to get parent process ID using Get-Process PowerShell

Display the Parent Process of a given Process

The Get-Process command in PowerShell is a well-known cmdlet to return basic process information. However, what it does not return is the parent process of a particular process. With the following script, one can find out the parent process of a process with ease. Provide the process name as a parameter and run the following script. 

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




Post navigation



    • Related Articles

    • Display Events with a particular Text

      Administrators often have to stifle through Windows logs to troubleshoot problems with their systems or applications. However, manually going through heaps of system log information to find out the root cause of an event can be quite laborious.   ...
    • Display the most recent error messages in the system logs

      Administrators often have to stifle through Windows logs to troubleshoot problems with their systems or applications. However, manually going through heaps of system log information is laborious. The following PowerShell script, when executed, will ...
    • Display maximum and minimum FreeSpace in a logical disk

      It is paramount for IT admins to check the available disk space in a particular system before pushing out an update or installing an application. However, to do so at scale can be intimidating, as it can quickly get out of hand.   With the following ...
    • Managing mailboxes and their quota limits in Exchange

      Management of the Microsoft Exchange environment in an organization is a comprehensive process. One of the various tasks is managing mailboxes, defining their quota limits, and identifying those that are over their given quota limit. This task can be ...
    • Create a shared folder

      Provisioning and managing shared folders through the native Windows process is a pretty straightforward process. However, things can get quickly out of hand when you need to manage multiple shares across multiple computers. With PowerShell, you can ...