Almost every week I get excited about a new tool. The tool of choice for the last week was Microsoft’s PowerShell. After my exposure to the linux shells, I started disliking the command prompt because of it’s simplicity. I am really happy that Microsoft has finally come up with something at least as good as the linux shells (I have not spent enough time to make any conclusions on whether it is better). Some things that I still don’t like is that there is no easy way to delete a complete word, like the CTRL-W in some of the shells, or event better the vi
mode! 🙂 Anyways, back to PowerShell. For those of you who have had early exposure to this product, PowerShell was originally called Monad, and has been around a little while. PowerShell is an object based shell, and one of its best features is the object pipelining support. I don’t want to explain all the PowerShell things because there are quite a few articles and documents on the web that do that; instead here are some uses.
So, the other day I was playing around with writing an expect
script to quickly upload a file to a client FTP server. During this process I had to kill the expect process a few times, not realizing that every time it was actually leaving ncftp
running in the background. Today my computer became a little slow because I had a lot of programs running. So, I started Task Manager by pressing CTRL, SHIFT, and ESC. Oh, that reminds me; the other day, I was surprised to find out that this shortcut key for running Task Manager is fairly unknown. Memorize it, it comes in handy! …Task Manager comes up and I see a ton of ncftp.exe processes running. I made this an exercise to learn PowerShell and decided that I was going to kill these processes using a PowerShell command. Well, after a few minutes and a few glances of the Quick Reference (part of the PowerShell install) I had a command to kill all of the ncftp process.
Get-Process | Where {$_.ProcessName -eq "ncftp" } | ForEach-Object { Kill %_.Id }
I know I could have saved a few minutes this time by individually killing the twelve or so instances of ncftp.exe, but where is the fun in that! No, more seriously, I made this an opportunity to sharpen the saw. I can see this knowledge coming in handy down the road.
Similarly, run the following command if you are curious about the actual paths of the executables that are currently running.
Get-Process | Format-Table -Property ProcessName, Path -AutoSize
Update: as mow points out in the comments, there is an easier way to accomplish my first task of stopping all instances of ncftp.
Get-Process ncftp | Stop-Process