Quick and Dirty Scripting

A blog that focuses on automating system administration tasks for Linux, Windows, and VMware ESX

Thursday, December 27, 2007

 

Update to VMware's Powershell Toolkit

 

Just wanted to throw this out there for anyone using VMware's Powershell toolkit. They released a new CTP on 12/26. The file version is 68764.  They've added a bunch of new commands such as Get-Inventory, New/Get-OSCustomizationSpec, Add-VMHost, Move-Datacenter, Move-Cluster, Find-EntityViews, etc . .

I need to find some time to play with these new commands. I do know that the base Get-VIServer and Get-VMHost do work with ESX 3.5 which is nice to see as well.

Until I have more scripts to share. . .

Labels: ,


Monday, November 26, 2007

 

VMware's Very Cool Get-Stat Command

 

Today I want to briefly show  you the power of the VMware's Get-State command.  With it you can grab statistics on any VI entity - ESX Host, Virtual Machine, or Resource Pool.  To use it, all you need to do is supply the entity you want to monitor and which statistics do you want to grab (common, CPU, memory, disk, or network). So let's get some stats on an ESX host.

 $vc = Get-VIServer "vc1.example.com"

$esx = Get-VIHost "esx1.example.com"

Get-Stat $esx -Memory -maxsamples 3 -realtime

MetricId             Timestamp                                     Value Unit
---------            ----------                                    ----- ----
mem.vmmemctl.average 11/26/2007 1:52:2...                              0 KB
mem.vmmemctl.average 11/26/2007 1:52:0...                              0 KB
mem.vmmemctl.average 11/26/2007 1:51:4...                              0 KB

Value       : 21.49
Timestamp   : 11/26/2007 1:52:20 PM
MetricId    : mem.usage.average
Unit        : %
Description : Memory usage as percentage of total configured or available memory
Entity      : VMware.VimAutomation.Client20.VMHostImpl

Value       : 21.49
Timestamp   : 11/26/2007 1:52:00 PM
MetricId    : mem.usage.average
Unit        : %
Description : Memory usage as percentage of total configured or available memory
Entity      : VMware.VimAutomation.Client20.VMHostImpl

Value       : 21.49
Timestamp   : 11/26/2007 1:51:40 PM
MetricId    : mem.usage.average
Unit        : %
Description : Memory usage as percentage of total configured or available memory
Entity      : VMware.VimAutomation.Client20.VMHostImpl

mem.active.average   11/26/2007 1:52:2...                          78988 KB
mem.active.average   11/26/2007 1:52:0...                          78988 KB
mem.active.average   11/26/2007 1:51:4...                          78988 KB
mem.granted.average  11/26/2007 1:52:2...                        2097504 KB
mem.granted.average  11/26/2007 1:52:0...                        2097504 KB
mem.granted.average  11/26/2007 1:51:4...                        2097504 KB

Get-Stat $esx -common -maxsamples 1 -realtime

MetricId             Timestamp                                     Value Unit
---------            ----------                                    ----- ----
cpu.usage.average    11/26/2007 2:05:4...                           4.86 %

Value       : 297
Timestamp   : 11/26/2007 2:05:40 PM
MetricId    : cpu.usagemhz.average
Unit        : MHz
Description : CPU usage in MHz over the collected interval. For hosts this can be represented on a per Virtual Machine
              basis as a stacked graph
Entity      : VMware.VimAutomation.Client20.VMHostImpl

mem.usage.average    11/26/2007 2:05:4...                          21.48 %

Value       : 105
Timestamp   : 11/26/2007 2:05:40 PM
MetricId    : disk.usage.average
Unit        : KBps
Description : Aggregated storage performance statistics. For hosts this can be represented on a per Virtual Machine bas
              is as a stacked graph
Entity      : VMware.VimAutomation.Client20.VMHostImpl

And finally,

$stats = Get-Stat $esx -common -maxsamples 1 -realtime

$stats. GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

Since the object returned to you is an array,this allows you to store and manipulate the return results - like

$stats[2]

MetricId             Timestamp                                     Value Unit
---------            ----------                                    ----- ----
mem.usage.average    11/26/2007 2:07:0...                          21.48 %

or $stats[2].Value

21.48

These values can then be piped into a table or graph to display the results.

Next week, I want to go back to something basic in Powershell - XML configuration. Powershell makes parsing XML documents very easy and I want to show how you can use this to create XML configuration files.

Labels: , ,


Wednesday, November 14, 2007

 

Creating a VM from a Template using Powershell

Yesterday, I posted that I was having issues creating a new VM from a template while using VMware's Powershell commands. It must have been the weather or something because today, it seems to be working without any issues. The following is how you can create a new VM from a template using Powershell. I did notice one interesting thing that I want to ask VMware about which I will mention at the end of this entry.

PS C:\Temp> $vc = Get-VIServer "vc.example.com"
There were one or more problems with the server certificate:

* The certificate's CN name does not match the passed value.

PS C:\Temp> $t = Get-Template -Server $vc
PS C:\Temp> $t[0]

Name Id
---- --
ESX3-WIN2K3SP2-ST... VirtualMachine-vm-23637

PS C:\Temp> $esx = Get-VMHost -Name "esx1.example.com"
PS C:\Temp> $esx

Name Id
---- --
esx1.example.com HostSystem-host-7523

PS C:\Temp> New-VM -Host $esx -Template $t[0]

cmdlet New-VM at command pipeline position 1
Supply values for the following parameters:
Name: vm-1

At this point, a Powershell progress bar appears and the progress of the deployment can be tracked.
The shell's focus is not returned until after the deployment is complete. The interesting thing is, that I can CTRL-C and cancel this Powershell command but the template continues to be deployed from within VirtualCenter. I am not sure how VMware will handle this situation but I would expect the deployment to be canceled once I cancel the Powershell command. I would love to hear any one else's thoughts on this matter as well.

Labels:


Tuesday, November 13, 2007

 

Creating a Virtual Machine with Powershell

Sorry for the delay in posting this week. I had out-of-town guests in all weekend so everything has been turned upside down. I would like to continue from last week and show how easy it is to create a new virtual machine with Powershell. Again you'll need the VMware Powershell management Snap-in before you have access to these commands.

To Create a Virtual Machine, you need to do the following:
1. Connect to your Virtual Center server -
2. Connect to the ESX Host where you want to create the VM -
3. Create the virtual machine -
4. If you want, you can specify options while you are creating the VM or you can use the Set-VM to modify the VM's specifications.

I tried to create a new VM from a template with the following steps, but I continually got an error while doing so. I guess this just goes to show that VMware is still developing this code and it has some ways to go.

1. Get all templates that VC knows about
2. Create new virtual machine from the first template
If someone could show me what I am doing wrong, that would be great.

Labels:


Archives

October 2007   November 2007   December 2007   January 2008   February 2008   April 2008   July 2008  

View Brian Denicola's profile on LinkedIn

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]