2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【PowerShell】プロセス一覧をStartTimeでソートする

Posted at

はじめに

地味にハマったのでメモ。

結論

Get-Processを実行した際、ヘッダ上にStartTimeは存在しない。
しかし、その状態でもStartTimeでソートするとちゃんとソートされる。

Ref. Format-Table (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs

>  Get-Process  | Sort-Object StartTime | Format-Table -Property StartTime, *
StartTime           Name           Id PriorityClass FileVersion HandleCount WorkingSet PagedMemorySize PrivateMemorySize VirtualMemorySize TotalProcessorTime SI Handles            VM       WS      PM NP
                                                                                                                                                                                                         M
---------           ----           -- ------------- ----------- ----------- ---------- --------------- ----------------- ----------------- ------------------ -- -------            --       --      -- --
                    Idle            0                                     0       8192           61440             61440              8192                     0       0          8192     8192   61440 72
2021/06/05 17:10:45 Secure System  56                                     0   23945216          188416            188416           2256896 00:00:00            0       0       2256896 23945216  188416 72
2021/06/05 17:10:45 Registry      108                                     0   35389440         9715712           9715712         121274368 00:00:01.5781250    0       0     121274368 35389440 9715712 52
2021/06/05 17:10:48 System          4                                 13643     147456          200704            200704           4001792 00:16:00.7812500    0   13643       4001792   147456  200704 72
2021/06/05 17:10:48 smss          432                                    53     897024         1089536           1089536          41521152 00:00:00.1875000    0      53 2203359744000   897024 1089536 24
2021/06/05 17:10:57 csrss         736                                   733    3862528         1933312           1933312          97402880 00:00:03.1093750    0     733 2203415625728  3862528 1933312 68
2021/06/05 17:10:59 wininit       908                                   165    5435392         1478656           1478656          69423104 00:00:00.1406250    0     165 2203387645952  5435392 1478656 40
2021/06/05 17:10:59 csrss         956                                  1000    6029312         4591616           4591616         134524928 00:01:18.8281250    1    1000 2203452747776  6029312 4591616 32
2021/06/05 17:10:59 services      984                                   843    9396224         6979584           6979584          69779456 00:02:27.7812500    0     843 2203388002304  9396224 6979584 00

詳細

Get-Processの結果にはStartTimeは存在しない。

> Get-Process

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    449      24    12104      22236      59.33  12456   1 Adobe CEF Helper
    779      95   178180      98720     116.56  12556   1 Adobe CEF Helper
                                  ..

Format-Listを使うと、StartTimeが存在するのが見て取れる。

> Get-Process | Format-List *
Name                       : Adobe CEF Helper
Id                         : 12456
PriorityClass              : Normal
...
StartInfo                  : System.Diagnostics.ProcessStartInfo
StartTime                  : 2021/06/05 17:11:45
...

StartTimeに限らず、Format-Listにある項目であればソート可能

>  Get-Process  | Sort-Object PrivateMemorySize | Format-Table -Property PrivateMemorySize, *

PrivateMemorySize Name             Id PriorityClass FileVersion HandleCount WorkingSet PagedMemorySize PrivateMemorySize VirtualMemorySize TotalProcessorTime SI Handles           VM       WS     PM  NPM
----------------- ----             -- ------------- ----------- ----------- ---------- --------------- ----------------- ----------------- ------------------ -- -------           --       --     --  ---
            61440 Idle              0                                     0       8192           61440             61440              8192                     0       0         8192     8192  61440  272
           188416 Secure System    56                                     0   23945216          188416            188416           2256896 00:00:00            0       0      2256896 23945216 188416  272

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?