Perfomance counter and instance names

Oleg Gussak 1 Reputation point
2020-08-11T08:48:05.37+00:00

Hi!
Are there any api functions to map process id with its instance name in the following performance categories without using counter "\process\id process"

  1. process
  2. http service request queues
  3. asp.net applications
  4. https service url groups
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,651 questions
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 34,421 Reputation points
    2020-08-11T15:38:27.36+00:00

    You might be able to use the command line that launched the process. Run a few notepad's, plug this code into an elevated Powershell_ise and run it. I think that you're going to need process id though. It all depends on what you are looking for.

    Note, I've found Scriptomatic to be useful when trying to write WMI scripts. It doesn't do Powershell, but I can easily translate from VB script.

    Scriptomatic-21-aka-shame-9cdc28b5

    cls
    $Notepads = get-process -Name notepad 
    ''
    "================ What powershell knows about your notepad's =============================="
    foreach ($np in $Notepads) {
        ''
        "-------------------- $($np.id) --------------------"
        $np| Format-List -Property *
    }
    
    ''
    "============== The command line that launched your notepad's ====================="
    foreach ($np in $Notepads) {
        "{0} - {1}" -f $np.Id, (Get-CimInstance Win32_Process -Filter "ProcessId=$($np.Id) ").CommandLine
    }
    
    ''
    "============== Performance counters ================"
    foreach ($np in $Notepads) {
        ''
        "-------------------- $($np.id) --------------------"
        Get-CimInstance Win32_PerfRawData_PerfProc_Process -Filter "IDProcess=$($np.Id) " | Format-List -Property *
    }
    
    0 comments No comments

  2. Rita Han - MSFT 2,166 Reputation points
    2020-08-12T07:29:37.04+00:00

    Hello,

    Add a registry value ProcessNameFormat under the following registry key and set its value to 2.

    HKLM\System\CurrentControlSet\Services\Perfproc\Performance  
    

    This will append the process identifier (PID) to the process instance name like this:

    17191-20200812-1.png

    Refer to Handling Duplicate Instance Names.

    Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.