1

I am trying to capture some data on CPU activity on a SQL instance.

Get-Process | Sort CPU -descending | Select -first 10 -Property ID,ProcessName,CPU

The PowerShell above give me the following output :

enter image description here

How do i modify the powershell to include a timestamp for each row. And output should look something like this.

enter image description here

1 Answer 1

4

You can add a calculated property to you output like this

Get-Process | Sort CPU -descending | Select -first 10 @{l="Time";e={get-date}},ID,ProcessName,CPU

The syntax for adding a calculated property is

 @{                  - start a script block
   l = 'label';      - choose a label for the property (not mandatory)
   e = {expression}  - formulate the expression you like evaluated
 }                   - close the script block

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.