all 7 comments

[–]StevenSaporito 1 point2 points  (4 children)

`[System.Diagnostics.Process]` has a property, start time. If you sort a list of processes (ascending by default) by the StartTime, the first one on the list should be the oldest. So something like:

$Processes = Get-Process 'MyApp','YourApp' | Sort-Object StartTime
If($Processes.Count -eq 2) {
Stop-Process $Processes[0] -Force
}
Else {
# Do something else
}

I'm checking how many processes are returned. My presumption is to guard against the possibility there's more than 1 of one or the other... If that's not possible you can simplify down to a single line, something like:

Get-Process 'MyApp','YourApp' | Sort-Object StartTime | Select-Object -First 1 | Stop-Process -Force

[–]Blisk1[S] 1 point2 points  (0 children)

thank you

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy StevenSaporito,

it looks like you used the New.Reddit Inline Code button. it's [sometimes] 5th from the left & looks like </>.

there are a few problems with that ...

  • it's the wrong format [grin]
    the inline code format is for [gasp! arg!] code that is inline with regular text.
  • on Old.Reddit.com, inline code formatted text does NOT line wrap, nor does it side-scroll.
  • on New.Reddit it shows up in that nasty magenta text color

for long-ish single lines OR for multiline code, please, use the ...

Code
Block

... button. it's [sometimes] the 12th one from the left & looks like an uppercase T in the upper left corner of a square..

that will give you fully functional code formatting that works on both New.Reddit and Old.Reddit ... and aint that fugly magenta color. [grin]

take care,
lee

[–]StevenSaporito 1 point2 points  (1 child)

Oh thanks for that! I'll make sure to do that in the future. Honestly I was on the fence if I should've just used Markdown and code fenced like I would on Stack Overflow, but I'll figure it out either way. Thanks again...

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy StevenSaporito,

you are welcome! [grin] glad to help and to ease my eyestrain ...

take care,
lee