I am using power shell to find out time when particular process( i.e notepad ) was started and exited.I am using to Get-Process to get status of application but $status.ExitTime does not get time when process was exited. How to get time when process is exited. I am running this in infinite loop so that power shell script does not end.
I have code snippet.
while ('doNotStop') {
$status = get-process notepad -ErrorAction SilentlyContinue
$status | Format-List *
$startTime = $status.StartTime
if($status) {
Write-Host 'Process is Running'
$status.waitforexit()
Write-Host 'Process startTime='$startTime',endtime='$status.ExitTime
}
else {
Write-Host 'Process is Not Running'
}
}