This sample defines a PowerShell function that lists CPU intensive processes running on a machine. If you call the function without any parameters it will list the top 5 CPU intensive processes. However, you can also pass to the function the number of items you wanted returned along with a name mask for matching processes.
Function Get-ExpensiveProcesses([int] $processCount = 5,[string] $optionalMask = "*") {
Get-Process $optionalMask | Sort-Object CPU -Descending | Select-Object -first $processCount
}
C:\Windows\system32> ListExpensiveProcesses
C:\Windows\system32> ListExpensiveProcesses 10
C:\Windows\system32> ListExpensiveProcesses 10 "*svchost*"