How-To Guides

Linux Users: Use the Powershell For LS, MAN, PS on Windows

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:

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!

Written by:Oliver Krautscheid Oliver is the founder and lead editor of this site. He is interested in finding new ways to break Windows, find common errors and help others to fix them. Aside from that, he loves to fully customize systems with Rainmeter and Dreamscene, find out more about ancient civilizations like the Chachapoya, sharpen his digital photography skills and create software with a small group of selected developers. If you would like to connect with him to discuss anything, send him a mail!