Saturday, June 23, 2012

Microsoft Powershell

Lately Windows PowerShell started getting a lot of interest from programmers at work.
I've been asked a few times what its for and is it useful.
I thought it would be a good opportunity to write a short introduction.

PowerShell is a task automation framework, consisting of a command-line shell and associated scripting language built on top of, and integrated with the .NET Framework.
Basically  it means I get a Microsoft scripting environment which provides one interface to Windows technologies like WMI, COM and .NET.

A new version of PowerShell is available on Windows 8 and can be downloaded here
as part of the Windows Management Framework 3.0 RC, so be careful.

So what can one do with PowerShell ?
Here are a few examples:

Like your regular command prompt, you have most commands your used to however in PowerShell i can also use stronger scripting command.
below I use ipconfig and pipe it to another command like in Linux

C:\PS> ipconfig | select-string -pattern 255
Subnet Mask . . . . . . . . . . . :

Windows PowerShell is actually a .NET Framework environment.
This means that you can use objects.
For example, when you get a service in Windows PowerShell, you are really getting an object that represents the service. When you view information about a service, you are viewing the properties of its service object. And, when you start a service, that is, when you change the Status property of the service to "started," you are using a method of the service object.  I can see the type of object by useing the get-member command
The following command sends the objects retrieved by a Get-Service command to Get-Member.
get-service | get-member 

Get-Member displays information about the service object, including the typename of the object and a list of its properties and methods.

   TypeName: System.ServiceProcess.ServiceController

Name            MemberType    Definition
----            ----------    ----------
Name            AliasProperty Name = ServiceName
RequiredService AliasProperty Name = ServiceDependedOn
Desposed        Event         System.EventHandler Disposed(System.Object,System.EventArgs)
Close           Method        System.Void Close()
Continue        Method        System.Void Continue()

Another cool feature is the whatif command.
I can issue a command, and ask what will happen if i run it.
PS D:\> Get-Process cmd | Stop-Process -WhatIf
What if: Performing operation "Stop-Process" on Target "cmd (12132)".

With PowerShell you can also write your own modules and commands.

If your a Microsoft programmer or and administrator, I recommend you start using Powershell if you havn't already and discover how simple and powerfull it can be.
A nice crash course can be viewed at the link below.

Windows PowerShell Crash Course | TechEd North America 2012

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Online Training from India. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.