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.
The Start-Process cmdlet allows you to run one or multiple processes on your computer from within PowerShell. It's designed to run a process asynchronously or to run an application/script elevated (with administrative privileges).
Using the Measure-Command cmdlet in PowerShell is an easy way to measure the run-time or execution time of a command. This can also tell you how long a custom function or an entire script takes to execute. Measure-Commandis a cmdlet that is easy to use and provides intuitive, actionable output.
As a one-liner you could use:
Get-Process ProcessName | select starttime
Do it like this:
(Get-Date (Get-Process explorer).StartTime).ToString('yyyyMMdd')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With