2

I am very new to Powershell. I need to get Page Faults and Disk IO of system while a particular process is running. I am able to get Page Faults but not able to get Disk IO. Can u guys help me please. Below is my code:

 $arrayDIO = @()
 $arrayPf = @()
 $cmdProcess = start-process cmd -passthru
   while (-not $cmdProcess.HasExited) {
        $arrayDIO += %{ (Get-WmiObject Win32_PerfFormattedData_PerfProc_Process).IOWriteOperationsPerSec }
        $arrayPf += %{ (Get-WmiObject Win32_PerfFormattedData_PerfOS_memory).PageFaultsPerSec }
    sleep 2
  }
 $arrayPf | Measure-Object -Average -Maximum -Minimum | Out-File  -Filepath C:\Details.txt
 $arrayDIO | Measure-Object -Average -Maximum -Minimum | Out-File  -Filepath C:\Details.txt -append
Avadhani Y
  • 123
  • 1
  • 1
  • 6
  • This is not a disk IO performance counter, by the way. It's a counter for process write operations (a quantity measured not in volume of data). Maybe pedantic, but do you mind if I update the Q? – john Jul 25 '13 at 21:01

1 Answers1

0

You are grabbing a performance counter that returns the process data for each individual process, plus all processes combined into one counter (_Total). You'll need to filter by the process name to get that specific process's performance data.

The reason you have no data is because the Get-WMIObject command returns an array of ManagementBaseObject objects, each containing the attribute IOWriteOperationsPersec but the array doesn't contain that attribute itself. You end up with an empty $arrayDIO array and therefore no performance data for Measure-Object.

See the updated code in line 5 from your example:

$arrayDIO += % { (Get-WmiObject Win32_PerfFormattedData_PerfProc_Process | Where-Object { $_.Name -eq "_Total"}).IOWriteOperationsPersec }

Where I have put "_Total" you can replace this with the actual process name you want to get the counter data for, or just leave it as-is to retrieve the total for all processes.

EDIT:

To make this work on Physical Disk Writes, you need to use a different performance counter (http://msdn.microsoft.com/en-us/library/windows/desktop/aa394308(v=vs.85).aspx).

Give this a try:

$arrayDIO += % { (Get-WmiObject Win32_PerfRawData_PerfDisk_PhysicalDisk | Where-Object { $_.Name -like "0*"}).DiskWriteBytesPersec /1024 }

/1024 converts the counter from Bytes to MB and "0*" selects the disk id. If you have multiple disks, you'll need to change this to the correct disk ID.

john
  • 1,995
  • 2
  • 17
  • 30
  • Thank u very much for the answer... I have to get Disk IO (MB/sec) and calculate the Average and Maximum... Does the above code you provided do the same? Please help me... – Avadhani Y Jul 26 '13 at 06:07
  • @AvadhaniY Do you want Logical Disk or Physical Disk? Physical disk will give you the total IO for a physical disk (the physical hardware). Logical Disk will will give IO for volumes (partitions). – john Jul 26 '13 at 07:19
  • I want for a Physical Disk IO... – Avadhani Y Jul 26 '13 at 07:22
  • @AvadhaniY I have updated my answer. I hope it works for you. – john Jul 26 '13 at 07:48
  • Thanks for the updated answer.. but i am not getting any output for the latest code line... FYI, i ahve only one Physical disk in my system... – Avadhani Y Jul 26 '13 at 08:08
  • Hmmm... Maybe post your updated code, and the output of the following command `Get-WmiObject Win32_PerfRawData_PerfDisk_PhysicalDisk | Select-Object Name`. – john Jul 26 '13 at 09:38