简体   繁体   中英

How to get the process start time in PowerShell

How do I get the process start time in PowerShell?

I tried this in the PowerShell prompt:

(Get-Process MyProcessName).StartTime.ToString('yyyyMMdd')

And this is the error I got:

(Get-Process MyProcessName).StartTime.ToString('yyyyMMdd')

You cannot call a method on a null-valued expression.
At line:1 char:1
+ (Get-Process MyProcessName).StartTime.ToString('yyyyMMdd_h ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

But when I do Get-Process MyProcess, I see my process:

> Get-Process MyProcess

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
   2906     132    81136      79132   889           20656 myprocess

And when I do 'Get-Date -format 'yyyyMMdd', it returns '20151207', so I think the date format is correct.

作为单线,您可以使用:

Get-Process ProcessName | select starttime

像这样做:

(Get-Date (Get-Process explorer).StartTime).ToString('yyyyMMdd')

以管理员身份运行:

Get-Process | select name, starttime | findstr your_process_name_here

It looks like you're not inputting the process name correctly ("MyProcessName" vs. "MyProcess"). You have

(Get-Process MyProcessName).StartTime.ToString('yyyyMMdd')

But it should be

(Get-Process MyProcess).StartTime.ToString('yyyyMMdd')

per your examples.

if you want to get the start time of a specific process use the following substituting "process name" with its name:

Get-Process ProcessName | select Name, StartTime

or to get all running processes' start times

Get-Process | select Name, StartTime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM