#sample.ps1 # #Demonstration of reporting on processes. # #Author: Pat Bailey #Input parameters are listed here Param( [int]$threshold, [string]$output ) #note: see chapter 7 of the online tutorial for comparison #and logical operators if (!$threshold -or !$output) #check for null value of parameter { "Usage: sample.ps1 -threshold 2 -output fileName" exit } #The get-process creates a list of process records #the % is shorthand for "ForEach" The ForEach operator loops #through each object input from the pipeline. The operation #in the curly brace refers to the current object with the #built in variable of $_ and in this case comparing the member #CPU (amount of CPU time used) to the threshold. On a true #comparison, it is printing out the default display of the current #object. Try breaking down this pipeline and running the $bigList = ( get-process | %{ if($_.CPU -gt $threshold){$_} } ) $tstring = "Total Count of " + $bigList.Length $tstring = $tstring + " Records." $tstring #$part1 = $tstring | ConvertTo-Html -Fragment #$part1 $part2 = $bigList | ConvertTo-HTML -Fragment ConvertTo-Html -Body "$tstring $part2" -Title "High CPU Use Report" | Out-File $output #hints on using the HTML output at https://technet.microsoft.com/en-us/magazine/hh127059.aspx