Sunday 2 October 2016

Introduction to Windows PowerShell – Part 1

Windows PowerShell is a windows command-line shell designed especially for administrators. PowerShell comes with interactive prompt and integrated scripting environment. PowerShell is kind of very much advanced version of your windows dos. PowerShell is a powerful scripting environment where you can do all sorts of things from managing files, users, exchange, active directory, SQL Server and the list goes on. This powerful tool is built on top of .NET Framework CLR and .NET Framework.

Learning PowerShell will make your life easier. Just imagine you have been given a task to update a set of property for all the users in the AD or you need to pull a report which has information about all the servers in your network like IP address, CPU, RAM, storage and list of services etc. Performing these kind of tasks manually will take hours of your time to complete it. Believe me using PowerShell you can do it with just few lines of code in very less time.
I have decided to write a blog series which will be helpful especially for DBA’s who loves to learn PowerShell. This is the first blog post in this series, we will see how to open PowerShell and run few basic commands.

Let's get started!!

How to open PowerShell ?

There are different ways to open PowerShell. Launch start menu and just search for PowerShell..







































Press Windows Key + R -> Type PowerShell and hit enter















If you open PowerShell, you will land up in a blue screen command line interface. Now let’s run some basic commands which we use to run in dos. Please note most of the command which you run in dos will work with PowerShell. 


























In Windows PowerShell we have a concept called as cmdlet (command-let). PowerShell has more than hundreds of cmdlets and you can also make your own cmdlets too. All cmdlets have a standard naming format verb-noun format. Now let’s see how get the list of cmdlets and find out what version of PowerShell you’re running

Get-command will give you list of all cmdlets.










$PSVersionTable gives you the version of your PowerShell

















Now we will see how to get the list of folders from a given directory using the actual PowerShell cmdlet. 

Get-ChildItem is the actual PowerShell cmdlet to list the folders.

















So now we saw that dir, ls and Get-ChildItem all gave us the same output. Let’s see how things are linked with each other. PowerShell has a concept called alias using which you make your code shorter by just calling the aliases. 
Get-ChildItem has three aliases. Now the question is how to get the details about these aliases. PowerShell help is the best place to look for information about any cmdlet and its always recommended to update your help on regular basis. How to update help, I will cover on different post.

So now let’s see what’s there in help for our Get-ChildItem cmdlet.

Get-help cmdletName is the command which will give you information about the cmdlet.




















There are ways to get the list of aliases for a given cmdlet. I will cover that in a different blog post.
In the next blog post we will see some more cmdlets and will focus on how things can be used in doing administrative tasks. I will be covering more specifically from server and database administrator’s standpoint.

Cheers,
Naveen

No comments:

Post a Comment