Warm tip: This article is reproduced from serverfault.com, please click

其他-如何在PowerShell中获取流程开始时间

(其他 - How to get the process start time in PowerShell)

发布于 2015-12-07 19:57:00

如何在PowerShell中获得流程开始时间?

我在PowerShell提示符中尝试了此操作:

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

这是我得到的错误:

(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

但是当我执行Get-Process MyProcess时,我看到了我的过程:

> Get-Process MyProcess

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

当我执行“获取日期格式”“ yyyyMMdd”时,它返回“ 20151207”,因此我认为日期格式是正确的。

Questioner
n179911
Viewed
0
sodawillow 2015-12-08 04:02:26

像这样做:

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