PageViews Last Month

Monday, 11 January 2016

Getting Started with PowerShell

Windows PowerShell is all about exploring .NET framework capability through the command line.Announced in 2006 it’s an admins paradise with the number of tasks that can be automated through the command line. The below table gives the release dates for various version of PowerShell.

PowerShell Version
Release Date
Default Windows Versions
Available Windows Versions
PowerShell 1.0
November 2006
Windows Server 2008 (*)
PowerShell 2.0
October 2009
Windows 7
Windows Server 2008 R2 (**)
PowerShell 3.0
September 2012
Windows 8
Windows Server 2012
PowerShell 4.0
October 2013
Windows 8.1
Windows Server 2012 R2
PowerShell 5.0
April 2014 
Windows 10

1. Why & what is Powershell.



Prior to Powershell VBscripts/unix scripts or DOS commands were encoded in batch files to be executed for performing repetitive task.Should there be a need to change the pattern of design the entire code would have to be re-written.This involved additional work, time and testing. Instead there was a need of a functionality wherein which you could write you own scripts give it a command name similar to that like DIR or MKDIR and have different parameter sets modifiable as per requirements.


PowerShell was invented with the idea of automating Microsoft GUI commands through a command-line interface.If you have any of the above windows version installed you will find the PowerShell under All programs -> Accessories -> Windows Powershell.  
PowerShell is both a command-line shell and scripting language. 








You may choose the ISE environment (x86 if your are running a 32-bit system) once you are familiar with the commands and wish to start scripting programs in PowerShell. PowerShell has its internal variables as well just like any other shell.  


Get-Variable would return the list.



All the commands written for PowerShell are called CMDLETS and they have the common structure of Verb-Noun. The native Windows-DOS and Unix commands work with PowerShell. For ef - dir,cls,ps,etc. Below are a few basic commands


1.      Get- help
2.      Get-command
3.      Get-verb
4.      Get-member
5.      Get-alias

Anything and everything can be learnt I believe with proper use of the above CmdLets .Get-Help  has a similar functionality as man command in Unix. Powershell works with all the wild card characters similar to Unix or DOS …Suppose you need to know the commands associated with process.I would type something like 

Get-Command *Process

and it would return the following output depending on the version.

To know the syntax and semantics of the usage of the command one could use.

Get-help Start-process 

and it would return the following output depending on the version.


As I stated earlier powershell returns object so if one wants to know what kind of object is returned and how to work further with the object  you could try

Get-Process | Get-Member 

and it would return the following output  depending on the version.

Wondering how the native commands works simple.Type the command

Get-Alias 

and you would get the below output depending on the version.

Get-verb 

lists the existing verb supported by PowerShell.

I'd suggest if you really want to learn first run the command Get-Help Get-Help and browse your way through the options. If you’re a keen learner this blog will just help you take your first step to the arena of automation through PowerShell.

Microsoft Virtual Academy provides and 6 hours intensive course by expert Jeffrey Snover, the inventor of PowerShell, and Jason Helmick, Senior Technologist at Concentrated Technolog to get started with powershell. 

My personal favorite are books by Don Jones. "Learn Powershell in a month of lunches" It helped me get started. I also recommend to go through the below link which provides a summary of PowerShell basics.
https://technet.microsoft.com/en-us/magazine/hh551144.aspx

Powershell has the ability to work with different modules like SQL server, Active Directory, Windows Administration, IIS. Advantages and usage of Powershell are limitless for you to explore.


1 comment:

  1. We've got a series from Mike Fal on SQLServerCentral as well: http://www.sqlservercentral.com/articles/powershell/135246/

    ;)

    ReplyDelete