Saturday, May 31, 2014

#13 : Find the path of applications with Powershell

There is a Windows command "Where" which tells use the location of executable applications. Such as, if you are looking for location of notepad, you can run :

where Notepad

Output:
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe

This helps you much when there are two versions of same executable and you want to know which will get priority. For example, in the above output, there are two entries for notepad.exe, but when you call notepad without providing full path, it will pick the one located in System32.

The same can be achieved in Powershell with the help of Get-Command cmdlet. This cmdlet will tell you the same output :

get-command notepad

CommandType     Name                                                     Definition
-----------     ----                                                     ----------
Application     notepad.exe                                              C:\Windows\system32\notepad.exe
Application     notepad.exe                                              C:\Windows\notepad.exe
You can adjust the output with format-table cmdlet. Such as, if you want to get output in form of Name and Definition only, you can try below :

get-command notepad | ft name, definition

That's all for today. Hope you liked this article. Thanks for reading!

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...