如何在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”,因此我认为日期格式是正确的。
像这样做:
(Get-Date (Get-Process explorer).StartTime).ToString('yyyyMMdd')