November 3, 2010

Managing VMWARE Server 2.0 via Powershell…

Although this article is slightly un-related to Exchange, it does have some relevance – particularly if you are like me and make use of VMWARE Server to create and test scenarios using VMWARE Server 2.0.

I have a number of virtual machines which I make use of day to day when compiling content for this blog – and as you might expect as the amount of VM’s has grown the complexity in managing them has also grown proportionally.

So given the above I have been looking at methods which I can use to simplify the management of the VMGuests on my home server.
I had looked at using VBScript in the first instance via the VIX API – however this seemed to be limited in what it could ultimately achieve at a basic level.

For example you could accomplish some fairly advanced management using VB and VIX – but the complexity of the code required to achieve complex tasks struck me as a false economy, in addition whereas I have been a big fan of VB over the years – with the event of Powershell I wanted a means which was more up to date.

So, after some research around the web I found (not that this will come as a huge surprise to most of you out there) that VMWARE had a free Powershell CMDLet set for vSphere called VMWare PowerCLI.

What might surprise you about the above is that it is compatible with VMWARE server 2.0 Host machines!

Considering the above I would like to share with you the process of installing VMware Power-CLI on your Host Server and some simple Powershell based management scripts that you can use to administer your virtual machines. It is important to note that this article is not designed to be a detailed analysis of Power-CLI – but more of an intro to what is possible – it is also worth mentioning that if you make use of vSphere or ESXi in larger scale VMWare deployments you can also use Power-CLI from your management machine.

What you will need

Before you install

Before you install the VMware-PowerCLI-4.1.0 you will need to ensure that you have installed both Powershell (at least version 1.0) and the VIX API.

In addition you should also make sure that you have set the Powershell Execution policy to remote signed – this can be done by opening a Powershell command window and typing in the following command:

Set-ExecutionPolicy RemoteSigned

VMware-PowerCLI-4.1.0 Installation

Remember that the VMware-PowerCLI Powershell extensions are for you VMware host or management machine – not guests – these are used to help you administer Guest VM’s.

Installation of the PowerCLI Client is very straightforward (provided that you have adhered to the pre-requisites in the above section) – from the location where you downloaded the Installer double click on the setup Icon – see below

pwrcli001

You will then be presented with the introduction screen as the installation loads (if you have missed any of the pre-requisite steps the installer will notify you) – see below

pwrcli002

When the installer has loaded – you will be presented with the welcome screen – click on the “Next” button to continue – see below

pwrcli003

You will then be presented with the “Patents” screen – click on the “Next” button – see below

pwrcli004

You will then be presented with the Licensing Agreement page – select the “I accept the terms in the licensing agreement” and click on the “Next” button – see below

pwrcli005

You will then be asked where you would like to install the Power-CLI binaries choose the location and then click on the “Next” button – see below

pwrcli006

You are now ready to install – click on the “Install” button – see below

pwrcli007

The installation will then perform the required tasks – see below

pwrcli008

When the installation is completed – click on the “Finish” button to complete the Wizard – see below

pwrcli009

Using the Power-CLI

There are a few ways in which you can launch Power-CLI (either via the Start Menu, shortcut entries on the Desktop or as I will demonstrate below via conventional Powershell).
Open a Powershell command window and type in the following command:

Add-PSSnapin VMware.VimAutomation.Core

see below

pwrcli010

You then need to connect to you VMWare 2.0 host server this is achieved (and it is assumed that you are running this command on the Host Server directly) by using the following command:

Connect-VIServer –Server localhost –Port 8333

and then press it is important to remember that the port will be the one that you assigned to you VMWare Server installation during setup – the default port is 8333 – if you changed this you will need to change the command above accordingly – see below

pwrcli011

If you receive the Certificate warning (which is present in the example above) you should be ok to ignore it – in essence this is caused by using a self signed cert for the VMware interface during installation – and therefore by definition will not be part of a trusted chain or have the correct host name.

Now that you are connected to your Host you are ready to begin managing the Server.

Simple Commands

To get started, perhaps one of the most straight forward commands is “Get-VM” – using this CMDLet will list all of the VM on your host and their respective status – see below

pwrcli012

As you can see above I have a VM running within the LAB (LAB-NAS-01) – to stop this machine all I need to do is type in the command

Stop-VM “LAB-NAS-01”

see below

pwrcli013

Conversely as you might expect you can use the

Start-VM “SEG-LAB-DC-01”

command to power on virtual machines.

There are over 160 commands within Power-CLI – which as you might expect allow you to manage pretty much every aspect of VMWare Server (and indeed all of the other ESX / vSphere product range) – but you might be thinking at the moment – I like the GUI interface – why would I want to move to the command line?

Well the answer to that is simple – where as it is true that you might not wish to use the command line for simple tasks which can be accomplished in the GUI (although I would argue that the GUI for VMWARE server is not the most stable therefore the command line might be preferable) – it is ideal to use for batch task.

Combining Powershell with Power-CLI give you the option to perform a number of task in bulk – for example mass creation of VM’s; multiple shutdowns of guest machines, and multi machine snapshots.

Advanced Use

Given the statement that I have made above in terms of being able to make use of Power-CLI – I have provided a script which allows for you to create a Simple Virtual machine from the command line. The script itself also give a very simple demonstration of how you can parse XML data from a file (this is used by the possible Guest O/S options) – you can update this file with the options which are located here: http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/New-VM.html

The script can be downloaded (with the XML file) at the end of the article.

To use the script download it (available at the end of the article) to a location on your Host VM Server, open a Powershell Window and type in the following command:

pwrcli014

You will be presented with the following screen – from the options presented chose a relevant datastore (via its numerical number) on which you VM will be stored:

pwrcli015

You will then be asked for the Name of the VM, number of CPU’s, amount of RAM & amount of Disk space to assign to the VM guest – see below

pwrcli016

You will then be presented with a list of available Guest O/S to assign to the VM (these are configured in the accompanying XML file which can be customised) – choose the number as appropriate – see below

pwrcli017

After choosing the number of the guest O/S you will be asked to provide a description for the VM – enter this in – see below

pwrcli018

The VM will then be created as per the options that you have selected – see below

pwrcli019

After the process has been completed you will be presented with a summary screen – see below

pwrcli020

If you then have a look within the VMware server administrative interface will now see that you VM is present – see below

pwrcli021

Inspecting the Notes section – you should see that the description that you provided within the script is present – see below

pwrcli022

Additionally you also see that the resources that you assigned to the machine are as specified – see below

pwrcli023

And indeed the guest O/S should be as you stipulated – you might need to upgrade the VM hardware – see below

pwrcli024

Download

You can download both the Powershell and XML file which performs the above from here:

pwrcli025Create VM & O/S XML File [ Zip 2KB]

Summary

I hope that someone will find this useful – and indeed please bear in mind that I have only touched the surface of what is possible when using Power-CLI for VMWARE – there is a chance that I will blog some more about this topic – if you would like to see some more thoughts please let me know.

SHARE:
Powershell 0 Replies to “Managing VMWARE Server 2.0 via Powershell…”