PowerShell_unix PowerShell is definitely gaining momentum in the windows scripting world but I still hear folks wanting to rely on unix based tools to get their job done.  In this series of posts I’m going to look at converting some of the more popular Unix based tools to PowerShell.

which

For this post, I’m going to tackle the Unix “which” command.  With the which command, you specify a file specification (ie notepad.exe, cs.*, etc) and it will scan your defined lookup paths in your environment for a file matching that specification.  Years and years ago I wrote a windows command line version of this that I still use almost daily.  So, it’s fitting that this is the first app I’m tackling in this series.

The logic behind this app is fairly simple: iterate through the values in your PATH.  For each directory in there, look for matches, and then print them out.  The following code performs the iteration logic in the Do-Which function and then writes the output of each match with the Write-FileInfo function.