如何在 PowerShell 中获取进程启动时间?
我在 PowerShell 提示符下试过这个:
(Get-Process MyProcessName).StartTime.ToString('yyyyMMdd')
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
(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
Run Code Online (Sandbox Code Playgroud)
但是当我执行 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
Run Code Online (Sandbox Code Playgroud)
当我执行 'Get-Date -format 'yyyyMMdd' 时,它返回 '20151207',所以我认为日期格式是正确的。
小智 5
作为单线,您可以使用:
Get-Process ProcessName | select starttime
Run Code Online (Sandbox Code Playgroud)
像这样做:
(Get-Date (Get-Process explorer).StartTime).ToString('yyyyMMdd')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17311 次 |
| 最近记录: |