【发布时间】: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
当我执行 'Get-Date -format 'yyyyMMdd' 时,它返回 '20151207',所以我认为日期格式是正确的。
【问题讨论】:
标签: powershell