Learning Powershell

February 9, 2011 — 1 Comment

Why I  wanted to learn Powershell

When installing and managing virtual infrastructures there are lots of repetitive tasks, when repetitive tasks are involved there is always the chance for mistakes. Mid last year I was working on sets of standards for installing and managing virtual infrastructures and it seemed the obvious progression to be able to automate some of these processes. This allowed me to help set standards and use time in a more intelligent manner.

Also in the era of “The Cloud” and “IT as a Service” the view of IT departments is starting to look increasingly on how we can streamline operations, offer automated workflows and deliver IT to the business as they need it.


The Who

Whilst attending the London VMUG in October last year I attended Alan Renouf’s Powershell session, I had also attended his session earlier in the year at a previous VMUG. What was different about this session is Alan had made it interactive, setting a number of tasks and allowing us all to connect into his home lab to try the scripts / one liners we had written. This is very much the way I learn, by being able to get hands on and try something make mistakes and correct them I absorb a lot more than simply reading a book or listening to a presentation. There was also a further bonus that I managed to persuade Jonathan Medd, Microsoft Powershell MVP to join our group for these tasks, Jonathan was very patient with my lack of knowledge and  explained a lot of the key elements of Powershell to me whilst we were working through the tasks.

I owe a lot of thanks to these guys for their help, their blogs and the passion for Powershell that they have passed onto me.

If you are wanting to learn more about Powershell be sure to check these guys blogs out

Alan Renouf – http://www.virtu-al.net

Jonathan Medd – http://www.jonathanmedd.net/

They have also been working on a book with a number of other Powershell / VMware experts that is due to be released in the next few months, more information can be found at the links below.

The website for the book – http://www.powerclibook.com/

Amazon – http://www.amazon.co.uk/VMware-VSphere-PowerCLI-Reference-Administration/dp/0470890797/ref=sr_1_1?ie=UTF8&qid=1296977693&sr=8-1


The How

Understand what you have to work with

A good place to start is by understanding the cmdlets you have to work with, the cmdlets are made up of a verb and a noun such as get-command and are the essence of what makes Powershell so user friendly when it comes to getting started. Different manufacturers will produce cmdlets for their products, you may have guessed already as you are reading this on my blog, but I will tend to focus on the VMware cmdlets, that are packaged as PowerCLI.

A good place to start to achieve this is the PowerCLI poster — http://www.virtu-al.net/2010/08/25/powercli-4-1-poster-and-quick-reference-guide/


With thanks to Jonathan Medd I have one of these on my office wall, which is always good to refer to whilst scripting.

The second way to get a rundown of the cmdlets is to run Get-VICommand from a PowerCLI window. This will list all the PowerCLI Cmdlets

Get vicommand

To get more information about anyone of these Cmdlets use the get-help [cmdlet name] -examples command

Get help

If you are in a situation where you don’t know the cmdlet you wish to use, you can always call upon get help using wildcards, for example if we wanted to create a virtual switch but didn’t know the cmdlet we could use

Get-Help *switch*

This would give us the following results

Get help2

We could then run Get-Help New-VirtualSwitch – Examples to find out how we use the cmdlet.

If you are looking for a run down of the Powershell 2.0 Cmdlets I would highley recommends Jonathan’s One Cmdlet at a time blog series and PDF.


Set yourself tasks or challanges

I found getting started learning Powershell to be quite challenging to start with as I couldn’t think of what to script. There are so many good scripts already out there already, that coming up with something original was a challenge. Just because there is a script already completed don’t let this put you off writing your own, you can then use the other scripts as inspiration or assistance when you get stuck.

VMworld PowerCLI Lab Manuals –

VMware have published the lab manual from VMworld 2010 on their PowerCLI blog, this is a very good document that not only has some challenges but also has the answers and explanations.


There is also a similar document for 2009


One of my challenges was to configure my new home lab server completely using PowerCLI, this gave me a good understanding of the PowerCLI Cmdlets

Have a lab

The key of being able to get your head around Powershell is being able to test your scripts before running them on a production environment. This can be a lot easier than it sounds, there are numerous examples of VMware Home Labs on the blogosphere, they could be made up of anything from ESX host in VMware Workstation, an affordable server to a spare blade in a production environment. If you are using the lab to test and build Powershell scripts the performance doesn’t usually matter all that much. I was able to roll out 30+ VM’s on my Microserver to test scripts, of course these servers had very small memory, cpu and disk requirments because I wasn’t worried about having an OS running, just the VM’s to manipulate, create and delete etc.

My home lab




Further home labs



There are also lots more examples that you will find my googling “VMware Home Lab” http://tinyurl.com/622kuyb

Training Material

As I have mentioned before I learn best when someone is able to walk through something with me, give me examples etc. That’s why I always find TrainSignal training so good,

TrainSignal have a number of Powershell elements in there vSphere series, I can highly recommend the vSphere Pro Training volumes 1 and 2. The Powershell elements are instructed by Hal Rottenburg (Microsoft Powershell MVP) and I found them really informative and meant I was able to follow along with the videos.

Vsphere pro series vol2 able

Hal also has a book available



VMware also have a Training Course that covers PowerCLI – VMware vSphere: Automation with vSphere PowerCLI [V4.x]


I haven’t been lucky enough to attend this course, but would love to!

Powershell / PowerCLI Blogs

VMware PowerCLI Blog – http://blogs.vmware.com/vipowershell/

Alan Renouf – http://www.virtu-al.net/

Jonathan Medd – http://www.jonathanmedd.net/

Luc D’s – http://www.lucd.info/

Hugo Peeters – http://www.peetersonline.nl/

Hal Rottenburg – http://halr9000.com/

The Tools

When I started trying to learn Powershell, I started by typing scripts in the Powershell console and trying to build my scripts in Notepad. This really doesn’t work very well and when I found a good script editor it changed my ability to write and troubleshoot scripts. I am personally using the PowerGUI Script Editor mainly because I already had it installed with the PowerGUI program itself.


Creating Scripts

I have found it easiest to create scripts by breaking it down into a number of smaller code blocks, addressing each of the goals one at a time, you can then concentrate on bringing the separate blocks together at the end. Whilst writing your scripts ensure you add meaningful comments as you go, this won’t only help others that may need to use the script but will help you when you come back to it 6 months later.

I hope you have found this blog post useful, please feel free to share your thoughts, tips and tricks.



One response to Learning Powershell


    i need to use VMware Vshere PowerCLi(powershell) in remote system can u help me
    i can run in local system . but cont use tat in remote system .. s there any connectionURI for that

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s