PowerShell Daily Dose: Get-Process

Get-Process cmdlet gets all the currently running processes on your machine. If you want to see the instances of a particular application, then you can specify the application name.

This gets you all the processes:


This gets you all the instances of Google Chrome web browser:

Get-Process Chrome

And the output will be like this:

Handles  NPM(K)  PM(K)   WS(K)  VM(M)    CPU(s)  Id       ProcessName
-------  ------  -----   -----  -----    ------  --        -----------
 142        19   27828   34220   206     1.05     2544   chrome
 142        19   28268   33976   217     1.33     2924   chrome

You can also use wildcards in application name. For example, if you want to see all the processes that have “sql” in their names, then you can do this:

PS C:\Learn> get-process *sql*

Handles NPM(K) PM(K)  WS(K)  VM(M) CPU(s) Id ProcessName
------- ------ -----  -----  ----- ------ -- -----------
 288     41     19152   5880 512    1.20 5668 SQLAGENT
 473     30     14572  11448 103    2.31 4232 sqlbrowser
 749    178    513208 322264 143   13.28 3028 sqlservr
  91      9      3408   7596  41    0.16 4260 sqlwriter

You can also specify other parameters like process id, handle etc.

For more information on syntax and usage, please refer to the documentation here.

Trivial Tip: Visual Studio – How to easily insert a carriage return in a resource (.resx) file string?

There are many ways to insert a carriage return (new line feed) in a resource string in a resx file but this is the simplest in my opinion.

Just open up the resx file in Visual Studio, edit the string content that you want carriage returns in, and just do a ‘SHIFT’ + ‘ENTER’ everywhere you need a carriage return. Yup, that simple.

For example, if you need


Just type “Hi”, followed by SHIFT + ENTER and then “There!”.

PowerShell Daily Dose: Get-Content

Get-Content gets the contents of the specified file. A simple usage example:

PS C:\test> Get-Content ps.txt
some random
text for
testing powershell
get-content cmdlet...

Note that you don’t have to type the whole cmdlet; you can use one of the aliases of this cmdlet: cat, gc or type.

This command returns a collection of objects. Each object represents a line of content in the file. You will start realizing the potential of this command as you learn more commands. For example, you can pipe the output of this command to a looping command like ForEach-Object.

There are several different options that you can pass on to the command. For example you can specify the number of lines to read, pass credentials to use, filter strings, include and exclude strings and many more. For more detailed info please check the get-content help page.

PowerShell Daily Dose: Get-Command

Get-Command helps you find/search for cmdlets. Simply typing in ‘Get-Command’ will give you a list of all available commands, which probably is not very useful. But if I want to, say, find all commands that contain ‘file’ in them, I can do this:

Get-Command -Name *file*

and the output will be something like this:

CommandType  Name                             ModuleName
-----------  ----                             ----------
Cmdlet       Add-BitsFile BitsTransfer
Cmdlet       Get-AppLockerFileInformation     AppLocker
Cmdlet       Get-WebConfigFile                WebAdministration
Cmdlet       Get-WebFilePath                  WebAdministration
Cmdlet       New-PSSessionConfigurationFile   Microsoft.PowerShell.Core
Cmdlet       Out-File                         Microsoft.PowerShell.Utility
Cmdlet       Test-PSSessionConfigurationFile  Microsoft.PowerShell.Core
Cmdlet       Unblock-File                     Microsoft.PowerShell.Utility
Application  DataProfileViewer.exe
Application  forfiles.exe
Application  openfiles.exe
Application  PROFILER.EXE

So we have a lot of commands from different modules. To just get cmdlets that contain ‘file’ from the module say ‘Microsoft.PowerShell.Core’, I can do this:

Get-Command -Module Microsoft.PowerShell.Core -Name *file*

And the output will be something like this:

CommandType  Name                            ModuleName
-----------  ----                            ----------
Cmdlet       New-PSSessionConfigurationFile  Microsoft.PowerShell.Core
Cmdlet       Test-PSSessionConfigurationFile Microsoft.PowerShell.Core

PowerShell Daily Dose: Get-Help

Today I have started really learning PowerShell which is notorious for its steep learning curve. After learning a few commands in depth I decided it was better if I documented my learning as a ‘one command a day’ feature. So here it goes…

(This is not a PowerShell tutorial, so I am not going to explain what a cmdlet is nor am I going to venture deep into explaining any specific term :).)
Today’s cmdlet:


This is the first cmdlet that everyone should probably learn. As the name suggests, this cmdlet gets you information about any Powershell command (including itself :)). The usage is ‘Get-Help <command>’.

For example, if you type “Get-Help Get-Help”, this is the output you see in PowerShell:

 Get-Help [[-Name] <string>] [-Path <string>] [-Category <string[]> {Alias | Cmdlet | Provider | General | FAQ | Glossary | HelpFile | ScriptCommand | Function | Filter | ExternalScript |
 All | DefaultHelp | Workflow}] [-Component <string[]>] [-Functionality <string[]>] [-Role <string[]>] [-Full] [<CommonParameters>]
Get-Help [[-Name] <string>] -Detailed [-Path <string>] [-Category <string[]> {Alias | Cmdlet | Provider | General | FAQ | Glossary | HelpFile | ScriptCommand | Function | Filter |
 ExternalScript | All | DefaultHelp | Workflow}] [-Component <string[]>] [-Functionality <string[]>] [-Role <string[]>] [<CommonParameters>]
Get-Help [[-Name] <string>] -Examples [-Path <string>] [-Category <string[]> {Alias | Cmdlet | Provider | General | FAQ | Glossary | HelpFile | ScriptCommand | Function | Filter |
 ExternalScript | All | DefaultHelp | Workflow}] [-Component <string[]>] [-Functionality <string[]>] [-Role <string[]>] [<CommonParameters>]
Get-Help [[-Name] <string>] -Parameter <string> [-Path <string>] [-Category <string[]> {Alias | Cmdlet | Provider | General | FAQ | Glossary | HelpFile | ScriptCommand | Function |
 Filter | ExternalScript | All | DefaultHelp | Workflow}] [-Component <string[]>] [-Functionality <string[]>] [-Role <string[]>] [<CommonParameters>]
Get-Help [[-Name] <string>] -Online [-Path <string>] [-Category <string[]> {Alias | Cmdlet | Provider | General | FAQ | Glossary | HelpFile | ScriptCommand | Function | Filter |
 ExternalScript | All | DefaultHelp | Workflow}] [-Component <string[]>] [-Functionality <string[]>] [-Role <string[]>] [<CommonParameters>]
Get-Help [[-Name] <string>] -ShowWindow [-Path <string>] [-Category <string[]> {Alias | Cmdlet | Provider | General | FAQ | Glossary | HelpFile | ScriptCommand | Function | Filter |
 ExternalScript | All | DefaultHelp | Workflow}] [-Component <string[]>] [-Functionality <string[]>] [-Role <string[]>] [<CommonParameters>]
 Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
 -- To download and install Help files for the module that includes this cmdlet, use Update-Help.
 -- To view the Help topic for this cmdlet online, type: "Get-Help Get-Help -Online" or
 go to http://go.microsoft.com/fwlink/?LinkID=113316.

This cmdlet can also be used with wildcard-ed nouns and verbs. For example, if you would like to see all the ‘Get’ cmdlets, you would use something like:

Get-Help -Name Get-*

That results in an output like this:

Name Category Module Synopsis
---- -------- ------ --------
Get-Verb Function
Get-Command Cmdlet Microsoft.PowerShell.Core ...
Get-Module Cmdlet Microsoft.PowerShell.Core ...
Get-Help Cmdlet Microsoft.PowerShell.Core ...

So that’s the Get-Help cmdlet.

The Law of Garbage Trucks

Now-a-days the comments section under online articles has become a more interesting place than the articles themselves :). You find all sorts of comments – funny, hilarious, weird, offensive, spam, well you know. But sometimes you find very well thought out comments too. Today I was reading an article on Yahoo.com about road rage in the US (check it out here). As usual went to the comments section and found a really great comment. A user named ‘Kusarigama’ shared a story about a cab driver in  NYC (don’t know if it was the commenter’s personal experience). It was a great story, so I wanted to share it here…

“Sixteen years ago I learned an important life lesson, in the back of a New York City taxi cab.

I hopped in a taxi, and we took off for Grand Central Station. We were driving in the right lane when, all of a sudden, a black car jumped out of a parking space right in front of us.
My taxi driver slammed on his brakes, skidded, and missed the other car by mere inches! The driver of the other car, the guy who almost caused a big accident, whipped his head around and started yelling bad words at us. My taxi driver just smiled and waved at the guy. And I mean, he was actually friendly!
So, I asked him, “Why did you just do that? This guy almost ruined your car and could’ve sent us to the hospital!”
And this is when my taxi driver told me about what I now call, “The Law of Garbage Trucks.”

“Many people are like Garbage Trucks. They run around full of garbage, full of frustration, full of anger, and full of disappointment. As their garbage piles up, they need a place to dump it, and if you let them, they’ll dump it on you. When someone wants to dump on you, don’t take it personally. Instead, just smile, wave, wish them well, and move on. You’ll be happier because you did.”

Wow. That really got me thinking about how often do I let Garbage Trucks run right over me? AND, how often do I then take their garbage and spread it onto other people: at work, at home, on the streets? It was that day I resolved, “I’m not going to do it anymore.”

Since then, I have started to see Garbage Trucks everywhere. Just as the kid in the Sixth Sense movie said, “I see dead people,” I can now say, “I see Garbage Trucks.” :)

I see the load they’re carrying … I see them coming to drop it off. And like my Taxi Driver, I don’t make it a personal thing; I just smile, wave, wish them well, and I move on.”

(All credit to Yahoo user Kusarigama for the great story :))

Do you Vote?

I have always been an avid complainer, always ready to complain about how bad things are in India. I would jump on any issue, post emotional comments on Facebook, discuss the issues rigorously and essentially do what most of the citizens of our great country do – NOTHING. I recently realized there is no end game to this. This is not a solution. We are just analyzing the problem, and not thinking about the solutions. So I started thinking about what needs to be done. Unfortunately I am too small a guy in this huge country to do anything significant. And I don’t think I am even qualified or capable of suggesting solutions to cleanup this country.

That lead me to think about the small things, but not insignificant, that I could do to at least bring about a little, no matter how little, change in people.

I started thinking about how bad our political system was. But quickly realized it wasn’t the politicians’ mistake that they were able to wield such enormous power. I realized it was us. We are handing the wrong people the power. Some are doing it directly and some are doing it indirectly. Both groups are doing this via one of the most powerful rights that a country could bestow on its citizens. The right to VOTE. Some people are using this right wrong. Some people are wrong by not using this right.

I think most of the educated populace doesn’t really care about elections. They don’t take voting seriously. If you take a moment to think about it, it becomes clear that if a majority of the non-voting reasonably thinking educated voters of this country take time to vote, they can tremendously influence the outcome of an election.

So I decided to try to do something small that a person like me can do – influence at least 10 people that I know to vote. If I can do that, I can be proud that I have done something for my country.

In our country people always come out in hordes to claim and yell about rights. But most of them don’t realize that a right comes with responsibility.

Are you ready to take responsibility? Or are you just content with having a meaningless right?