When you start to become familiar with Linux, you tend to look for similar functions on Windows 7. Heck, the last time I opened up a command shell the first thing was that I entered PS AUX. Obviously, that did not work ;) Here’s how you can use some Linux functions on Windows.
Short PowerShell Intro
Please note you may have to run it with elevated rights and execute the command set-executionpolicy remotesigned to allow the execution of scripts on your system.
If you have never used the PowerShell before, here’s how to get started.
1. Step Open the Windows Powershell, on the Start Menu it’s listed under Programs/Accessories/Windows PowerShell/Windows PowerShell
2. Step Enter PS which is now similar to Linux listing all processes that are currently running.
(Loving the blue background of the PowerShell!)
3. Step Now, what’s very cool, other commands like man also work. So let’s do a quick man PS to learn more about the PS syntax in the PowerShell. As you can see PS accepts the parameter ID to filter processes by ID. Process VLC has the ID 5144 for example, so let’s filter for that ID:
PS -id 5144 grabs the VLC process:
4. Step Now, that’s not very useful. How about a sorted list with the processes using the most memory at the top. Do that you have to use the paramter “sort-object” to sort stuff and the argument WS (which is the memory). Use either descending or ascending, depending on your needs.
ps | sort-object WS –descending
5. Step Ok, so you may ask what the fuss is all about? The task manager can do the same for you without entering all those commands. But what if you want to write a Windows Powershell script that kills a specific process whenever it reaches a certain memory value? The task manager can’t do that, unless you use a 3rd-party task manager for Windows 7 that includes such a feature.
6. Step Now, just to show you how similar the Windows PowerShell is to the Linux shell, we are going to export the results into a text file. Simply enter:
ps | sort-object WS –descending > C:/temp/memory.txt
7. Step Unfortunately, grep is not available, the Windows equivalent is findstr (a tad longer, but oh well)
8. Step So, let’s say you want to “grep” only a specific value on that list of processes you can use findstr. Keep in mind, that findstr is case-sensitive! So PS | findstr VLC won’t work!
That was a little introduction to the Windows PowerShell. I hope you find this interesting and when I have time I’ll write some scripts to grep some important value at specific times and publish them on this site. So, stay tuned!
Basic Linux Commands That Work In Windows PowerShell
> (output stuff into … /path/to)
Alternative Solutions: Auto-Repair Your PC And Drivers
Trending On Windows Themes .Net