How to Get Process Perf Data with brief logic?

Hi

I’m trying to get Process PerfData with this script in 2008 NT SP2.

but this consume cpu usage so much than i expected because of Get-WmiObject command.

i don’t have any idea to change this code…

i need some help please

$cpuCores = (Get-wmiObject -class win32_processor |measure-object -sum numberoflogicalprocessors).sum
$tops = Get-WmiObject Win32_PerfFormattedData_PerfProc_Process |select-object -property Name, @{“Name” = “CpuUsage”; Expression = {int}}, CreatingProcessID, IDProcess, @{“Name” = “Memory”; Expression = {int}}, StartTime, Owner |? {$.Name -notmatch "^(idle|total|system|svchost.*)$"} |Sort-Object -Property “CpuUsage” -Descending|Select-Object -First 10
$handlelist = Get-Wmiobject -class win32_process | select-object HandleCount, ProcessId, @{“Name” = “Owner”; Expression = {$
.GetOwner().user}}, @{“Name” = “starttime”; Expression = {$
.ConvertToDateTime($_.CreationDate)}}
$r =“0 Script_Cpu_Top_List - OK : cputoplist=[COMMAND,%CPU,PARENTID,PID,MEMORY,STIME,USER”

foreach($i in $tops){
$id=$i.IDProcess
$handle= $handlelist | where-object {$_.ProcessId -eq $id}
[string]$starttime = $handle.starttime
[string]$owner = $handle.Owner

$owner_start = $owner.IndexOf("") + 1
if ($owner_start -gt 1)
{
$owner_end = $owner.length
$owner = $owner.substring($owner_start,($owner_end-$owner_start))
}
$i.owner=$owner
$i.starttime=$starttime
$temp = $i.Name,$i.CpuUsage,$i.CreatingProcessID,$i.IDProcess,$i.Memory,$i.starttime,$i.owner -join “,”
$r="$r^$temp"
}
$r=$r +"]"
$r