Powershell basics part 1 – Getting started with powershell

In this post I will write about basic things that you need to know in order to work with windows powershell. I’ll start by writing some simple commands and the basics in order to interact with PS. We will do more complex stuff in a later post.
When you start powershell it will start in the default directory and it will be something like “PS C:\users\your-username\”. From here you you type Get-Childitem you will see the contents of the directory. Same thing appends if you write ls or dir. Microsoft build powershell in a way that both Microsoft and Linux users can operate with it because some commands from Linux were added to powershell.Below are the three commands:

Get-ChildItem command
From these three commands you have to understand that Get-Childitem is the cmdlet and ls and dir are the alias names of the cmdlet. It is easier to remember a shor name like dir than the whole cmdlet. Microsoft has build in powershell over 100 cmdlets and the majority of them have at least one alias.
If you type Get-Command, powershell will return a list with cmdlets, functions and aliases. For example if you can’t remember exactly a function’s name you can write Get-Command to look for that particular function.The commands are not key sensitive. Another useful thing is the “TAB” key. If you only remembered a portion of a cmdlet you can type that portion and by pressing “TAB” key powershell will try to auto-complete your cmdlet name. For example if you type Get-C and then press the tab key powershell will write Get-ChildItem. Pressing again tab key powershell will display the next cmdlet in alphabetical order (in this case Get-Cluster).
Now type Get-Command *.msc. Powershell will display all the applications that have the .msc extension
Get-command Powershell
If you type Get-Command *.exe it will display applications that have de .exe extension:
Get-command Powershell
Ok now let’s start with some other commands. If you have for example a problem with some processes that run on you computer or you need to find some information about one process, in powershell you can use the function Get-Process. Ok now let’s type this function in powershell:
Get-Process Powershell
In this output you can see a part of the processes that run on my computer.
Another useful cmdlet is Get-Help. You can use this cmdlet to display other cmdlets information. Now if I type Get-Help Get-Process powershell will display the following:
Get-help command
Now I see that outlook runs on my computer so I just want to select this process so I will type Get-Process -ProcessName outlook:
Get-Process Powershell
The same thing happens when you type Get-Process outlook because the -ProcessName is the first parameter in Get-Process function. The Get-Process o* will display all the processes that start with o:
Get-process command
If I write Get-Process *o powershell will return processes that end with o and if I enter Get-Process *o* it will return processes that contain the letter o inside.
Get-process command
In the next powershell tutorial I will continue with some basic things and later I will try to do some scripting.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s