1

I have the following output from a cmdlet in powershell, I would like to extract timestamp from output so that I can select jobs which has elapsed time > 24 hours

Command : Get-JAMSEntry -Name * -Server xxxxxx -State Executing

Output :

Entry  Name                   Description
-----  ----                   -----------
1     Sample                  Executing, elapsed time: 602.18:57:06.
3     Sample                  Executing, elapsed time: 481.18:57:02.
5     Sample                  Halted , elapsed time: 484.18:56:58.
7     Sample                  Hold, elapsed time: 680.18:56:55.
7     Sample                  Executing, elapsed time: 680.18:56:54.
7     Sample                  Executing, elapsed time: 680.18:56:53.
9     Sample                  Halted, elapsed time: 666.18:57:09.
1     Sample                  halted, elapsed time: 684.18:57:01.

Appreciate the help.

Thanks

1
  • Your elapsed time format seems weird. Hours as float, the fraction always .18 ? If hours are a float why :mm:ss? In general I'd use a select to split Description into calculated properties State and ElapsedTime. Commented May 23, 2018 at 3:33

1 Answer 1

1

When you pipe the output of your command to a Select-Object which inserts calculated properties by splitting the Description first at the , and then at the : like this:

Get-JAMSEntry -Name * -Server xxxxxx -State Executing |
    Select-Object Entry,Name,@{n='State';e={$_.Description.split(',')[0]}},
        @{n='ElapsedHrs';e={($_.Description.Split(',')[1]).Split(':')[1].Trim()}}

you'll get this output:

Entry Name   State     ElapsedHrs
----- ----   -----     ----------
1     Sample Executing 602.18
3     Sample Executing 481.18
5     Sample Halted    484.18
7     Sample Hold      680.18
7     Sample Executing 680.18
7     Sample Executing 680.18
9     Sample Halted    666.18
1     Sample Halted    684.18

you can further reduce with an appeded

|Where-Object {[double]$_.ElapsedHrs -gt 670}

to get only matching values

Entry Name   State     ElapsedHrs
----- ----   -----     ----------
7     Sample Hold      680.18
7     Sample Executing 680.18
7     Sample Executing 680.18
1     Sample halted    684.18
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.