Reputation: 20291
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.
Upvotes: 7
Views: 28589
Reputation: 13
if you want to get the start time of a specific process use the following substituting "process name" with its name:
Get-Process ProcessName | select Name, StartTime
or to get all running processes' start times
Get-Process | select Name, StartTime
Upvotes: 0
Reputation: 21
Run as admin:
Get-Process | select name, starttime | findstr your_process_name_here
Upvotes: 2
Reputation: 91
As a one-liner you could use:
Get-Process ProcessName | select starttime
Upvotes: 9
Reputation: 245
It looks like you're not inputting the process name correctly ("MyProcessName" vs. "MyProcess"). You have
(Get-Process MyProcessName).StartTime.ToString('yyyyMMdd')
But it should be
(Get-Process MyProcess).StartTime.ToString('yyyyMMdd')
per your examples.
Upvotes: 1
Reputation: 13176
Do it like this:
(Get-Date (Get-Process explorer).StartTime).ToString('yyyyMMdd')
Upvotes: 4