Sunday, 6 July 2014

Starting PowerShell from the Basic Commands !

I am giving some very basic powershell cmdlet for the beginners.

You will be able to understand how to perform each and every command available in PS using help command. Before using powershell help you have to update the help with latest update. Update help is the new features available in PowerShell 3.0. Not available in previous version of PS. Update-help is the command used to update the help content. I am giving some example for updating help.

# PowerShell 3.0 Updateable Help.
Below is the command to update help directly from Internet..

Update-help -force

Do you need any help on getting all the powershell commands ???
If YES just go ahead and open powershell and type Get-Help. This is the first cmdlet every administrator should learn.

# Remember to run powershell as "Run as Administrator" (As the files will be stored under root file which is restricted by default)
# Get-help Update-help Will provide more details about how to update help

Force is using to update the help file forcefully.

We can save the help file using save-help cmdlet. This will allows you to download the newest help files for windows powershell and save in a specified directory.This feature lets you to update the help file on computer that do not have Internet availability.
Below is the cmdlet used to save the help-files and update from saved place.. We have to specify the UI Culture  while downloading the help files. (Get-UICulture is the command to get the UICulture of the system)

Save-Help -UICulture en-US -DestinationPath C:\Users\vivek\PSHelp -Verbose
Update-Help -SourcePath C:\Users\vivek\PSHelp -Verbose


Can you remember all the cmdlets in powershell ???

If NO, get-command will help you to retrieve all the available powershell commands.If you remember any words in the command, you can easily retrieve the command. But it will not display the additional parameters and display all the command in console by default.

# Out-GridView : This cmdlet will display the output in  different windows and will help you to read it properly

Get-Command Get-Help
Get-command get-exe*


Get-Member is an essential command for discovering more about a PowerShell objects.As you can see, powershell output shows us some of the default properties, not all. We can use get-member cmdlet to retrieve all the properties of an object. More over we will be getting all the methods of an object by using get-member.

Get-Process | Get-Member

GM is the alias for Get-Member

Saturday, 5 July 2014

Basic understandings about Windows PowerShell.

My goal with this post is to start from beginning and try to give some basic idea about PowerShell. This is not a comprehensive session..

Windows PowerShell is a task automation and object oriented management engine based on .NET Framework which is designed especially for system administration and automate batch processing. PS is Object Oriented, but that doesn't mean you have to become a programmer to use it. PS is an extendable command shell as well.

What is Powershell ???

CMDLETS : Cmdlets are the native powershell commands in powershell environment. Cmdlet follows a Verb-Noun naming system with self-descriptive. Example : get-help

PIPE LINE (|) OR (¦) : Windows powershell pipeline takes the output from one command and sends it as an input of another command. In simple word, pipeline combines commands, filtering and giving the required output.

EXTENDABLE : This means, we can add values to this environment by extending it with our own commands (cmdlets).

Miss understandings of PS :
Powershell is NOT just a simple scripting language
And NOT just an advanced CMD Prompt.

PowerShell Versions

PS 1.0 : Released in 2006 for Windows XP SP2, Windows Server 2003 and Windows Vista.
PS 2.0 : Released in 2009 and Integrated with Windows-7 and Windows Server 2008R2
PS 3.0 : Released in 2012 and Integrated with Windows-8 and Windows Server 2012. Available for Windows-7 as well
PS 4.0 : Released in 2013 with new featured like Desired state configuration etc:
PS 5.0 : Released in 2013 with new features like class definition etc:

How to Use Powershell ?

Powershell engine is a set of .Net framework classes stored in a DLL file. You can not interact with it directly.
When we talk about "Using Powershell" we are most often talking about using it through a host that looks like command-line.  Microsoft provides two host for that purpose..

Console and ISE (Integrated Scripting Environment).

Console(PowerShell.exe) is an application that runs in command line and ISE is basically a graphical powershell application which is using for scripting purpose and we can have different run-space in a single window to run multiple scripts.Power GUI and SAPIEN PS Editor are the examples of some other third party host which enables more features.

Powershell and old command prompt (cmd) use the same underlying console technology, which means that you can type powershell in command prompt and cmd in powershell to switch the other shell. Exit will revert back the starting shell.

What is 64-Bit and 32-Bit Console ?

This is basically pointing to powershell extensions. If you are loading an extension, you can only load which is built on the same architecture. The 64-Bit shell can only load 64-Bit extension. And if you have 32-Bit extension you have to load 32-Bit shell.

Is Powershell available in all the OS by default ?

No. Windows Powershell is not available in all Operating system by default. It is available from Windows 7 and its latest and from windows-2008 R2 and its latest.We can download and install powershell in Windows-XP, Windows-Vista and Windows-2003. PowerShell version 5.0 is the latest release from Microsoft.

Why Should we learn PowerShell ?

  • Believe it or not, As per my experience from past one year using the command line made my life easier. Which meas that, I completed a task which required 6 hours in 10 Minutes by writing scripts. :) 
  • Almost all the latest products from Microsoft can be manageable by using powershell, like System Center Products, Active Directory, Exchange Server, SQL, Share Point Etc :
  • As we all know, there is a big competition for new IT jobs that are available. Therefore  its better if you can list Windows Powershell among your skill set.