Sunday 10 January 2010

First Post of Learn-Powershell

Welcome to my first post on my Powershell Blog. I am currently in the process of learning powershell.

In this first blog I will explain the basics of powershell including how to get it.

How to get Powershell
The First thing to note is at time of writing the current version of powershell is version 2.0 which ships with Windows server 2008 R2 and Windows 7. For other operating systems it is download able as part of the Microsoft Windows Management Framework from http://support.microsoft.com/kb/968929 or by searching the web for "Microsoft Management Framework". If you search for "Powershell 2.0" then you will find the CTP (Pre-Release) version.

What is Powershell?
Powershell is a (fairly) new scripting and command prompt environment for managing windows clients; servers; server functions such as Exchange 2007 and later; SQL Server 2008 and later; and Microsoft's System Center tools such as Virtual Machine Manager. It is also being used by 3rd party companies like VMware in ESX server.

The eventual aim is for administrators to know powershell and then everything can be done through powershell either in the command line or through scripts (*.ps1 files) which are command line inputs but made to run in an automated way to save typing and allow for scheduling. (If you are used to scripting using *.BAT files then you will understand the similarity with the powershell command line and how to script for it as its similar to that of the relationship between the classic windows command prompt and batch files.)

Where do I start?
  • First place to start is by installing it and get a shortcut to it somewhere accessible - you will want to spend lots of time using it. The best way to start to know what powershell can do is to use it. From now on if you want to use command prompt, don't, open powershell. All you want to do in command prompt is abalible from powershell and generally with the same command names as an alias of the powershell name. (ie. Set-Location uses the more familiar cd or chdir command found in windows and Linux).
  • Once you are started using powershell for your basic day-to-day tasks like ipconfig, file management, etc. you can work your way onto the new powershell commands. These are always formatted in verb-noun. A couple to get you started are Get-Command and Get-Help. A useful feature of V2 is tab completion, start writing a command, hit tab until you find the one you want, if you overshoot then shift + tab will take you back up. Try typing get-comm and hitting tab - it will give you the get-command option. The more you give it the more refined the ablible commands you tab through will be. To find out the availible verbs just type verb.
  • Now you have the hang of using powershell as a replacement for command prompt then you can try writing scripts. There are many ways you can write and edit scripts. You can use your basic text editor such as Notepad.exe or a more scripting focused text editor like notepad++. Personally I am finding the Windows Powershell ISE (Intergrated Scripting Environment) very useful as you can select sections of text and run that or run the whole thing from the one window and imidiately see the output. There are lots of ISE's avalible but this is a good one to start on as it's free and downloads with PowershellV2.
  • To allow scripts to run after you first install you'll be required to input the command "Set-ExecutionPolicy" hit enter and it will ask you to supply the value: The recommended option is "RemoteSigned". To read more on this option type "help Set-ExecutionPolicy".
  • The final getting started tip for this blog is Get-Member. Get-Member will help you know what you want to use in your command. To use it simply type the command you want to use and follow it with the pipe symbol ( | found above the \ key)and get-command like this: "Import-Csv | Get-Member" will tell your what methods are avalible and what NoteProperties (field Names) are ablible for that file.
Where can I find out more?
There are many places to go to find out more of what to do with powershell. I will be continuing this blog as I go through my travels of learning powershell and hopefully pass something useful on like this.
Other places I would recommend to go include:
For now I hope I've got you started ok.
Thanks for reading this blog and hope you enjoy learning powershell.

No comments:

Post a Comment