Powershell expression to check the correct instance of a process

To show all the processes that have a MainWindow title defined, run…

get-process | where {$_.MainWindowTitle} | Select ID,Name,MainWindowTitle,StartTime,@{Name="Age";Expression={(get-date) – $_.StartTime }}

This can be useful to see the correct instance of a process as well as see when a process started – StartTime property . The expression creates a custom property called Age which returns a TimeSpan object. The value is calculated by subtracting the StartTime value from the current date and time as returned by Get-Date.  The expression will return information like this:

Id              : 3172
Name            : taskmgr
MainWindowTitle : Windows Task Manager
StartTime       : 10/22/2009 10:31:05 PM
Age             : 09:22:53.1844560

Since Select-Object is used, so you can add on to the expression to pipe it to another cmdlet like Out-File or Export-CSV.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: