Alias to open latest log file in Windows Power Shell

Few days ago I’ve posted an alias to open latest log file of your application in bash shell. Same is possible on Windows environment if you use Windows Power Shell command interpreter. What you have to do is edit your profile.ps1 script and add a new function:

set-alias ed "C:/Program Files (x86)/Notepad++/notepad++.exe"
$global:app = "D:/MyApp"
function log {
   $myfile = ls $app/logs/*.log | sort -property lastwritetime | select -last 1
   ed $myfile
}

Of course change value for ed to your favorite editor/log viewer.
Here’s where you can read more about PowerShell profiles:
http://msdn.microsoft.com/en-us/library/bb613488(v=vs.85).aspx

Now just restart shell and execute log command.

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: