#requires -version 2.0 #Jeffery Hicks #http://jdhitsolutions.com/blog #Now available: #Windows PowerShell 2.0: TFM by Don Jones & Jeffery Hicks (SAPIEN Press 2010) Function Get-PerfTime { Param ([scriptblock]$expression, [int]$interval=1, [int]$max=10 ) 1..$max | foreach { $i=($_/$max)*100 Write-Progress -Activity "Performance Testing" ` -Status "Repeat: $max Interval: $interval MS" ` -CurrentOperation $expression ` -PercentComplete $i (Measure-Command -Expression $expression).TotalMilliseconds sleep $interval } } #end function #edit these values $computername="coredc01" #sleep interval in seconds $sleep=1 #max number of tries $max=100 #create a PSSession for later $session=New-PSSession -ComputerName $computername #define a standard scriptlblock with a cmdlet that supports -computername $Test1={get-process -ComputerName $computername } #define a WMI equivalent $Test2={Get-WmiObject -Class win32_process -ComputerName $computername} #define a test using Invoke-Command. You can reuse $Test3={invoke-command -ComputerName $computername -ScriptBlock {$Test1}} #define a test with Invoke-Command and PSSession $Test4={invoke-command -Session $session -ScriptBlock {$Test2}} $Test5={invoke-command -Session $session -ScriptBlock {$Test1}} #get data $Test1,$Test2,$Test3,$Test4,$Test5 | foreach { $raw=Get-PerfTime -max $max -expression $_ -sleep $sleep $avg=($raw | Measure-Object -average).Average New-Object PSObject -Property @{ Computername=$computername Repeat=$max Expression=$_ Average=$avg RawData=$raw } } #end ForEach #clean up the PSSession Remove-PSSession $session write-host "Finished!" -ForegroundColor Green #end of script