Category Archives: VMware

Quick Stats from VMware for reports

I wrote another quick script today as my powershell skills grow!

The following script can be used to give you a JPG outputted graph of some stats that you can choose, handy for reports.

It can easily be adjusted to perform stats on the ESX servers (vmhost) as well.

Example output (My Test server names have been blurred):

Chart

connect-VIServer yourserver

# Set the following 3 variables for your needs
# Example stats are:
# % CPU Usage – cpu.usage.average
# Mhz CPU Usage – cpu.usageMHZ.average
# % Memory Usage – mem.usage.average
# Kbps Network Usage – net.usage.average
# Kbps Disk Usage – disk.usage.average

$Caption = "CPU Usage"
$Stat = "cpu.usage.average"
$NumToReturn = 20

$categories = @()
$values = @()
$chart = new-object -com OWC11.ChartSpace.11
$chart.Clear()
$c = $chart.charts.Add(0)
$c.Type = 4
$c.HasTitle = "True"
$series = ([array] $chart.charts)[0].SeriesCollection.Add(0)

Get-Stat -Entity (Get-vm) -Stat $stat -MaxSamples 1 -Realtime |Sort-Object Value -Descending | Select-Object Entity, Value -First $NumToReturn | foreach-object {

$categories += $_.Entity.Name
$values += $_.Value * 1
}
$series.Caption = $Caption
$series.SetData(1, -1, $categories)
$series.SetData(2, -1, $values)
$filename = (resolve-path .).Path + "\Chart.jpg"
$chart.ExportPicture($filename, "jpg", 800, 500)
invoke-item $filename

ESXi Free from 28 July

Today, VMware is taking another step towards making virtualisation ubiquitous by announcing that VMware ESXi will be available for download at no cost as of the week of July 28, 2008.

VMware has always believed that virtualisation needs to be ubiquitous. Since 2001, VMware has provided the industry’s most popular and reliable hypervisor used by more than 100,000 customers. During this evolution, partners like you have been critical in educating and delivering virtualisation to customers of all sizes. In December 2007, VMware announced significant improvements with ESXi – its third-generation, stand-alone hypervisor. With its smaller footprint and OS-independence, ESXi ensures even higher levels of security and reliability while making virtualisation easier than ever to deploy.

More info can be found here http://www.chriswolf.com/?p=175

Give the users a console again

Granting Console Access and Power On/Off functions to your Users

Sometimes a user will complain that they need console access to there servers or permission to turn on/off or reset there machines if there is a problem, as the servers become virtualised this can be achieved in a number of ways, I have documented a couple of these ways below…

  1. Apply the correct permissions for the user you wish to access the virtual machine limiting them to there required security permissions.

If you’re using VirtualCenter, you can use roles and groups to assign permission to users such that they would only see the VM’s that they have permission to and could have various levels of rights over those VM’s. This is covered in depth starting at page 261 here – http://www.vmware.com/pdf/vi3_35/esx_3/r35/vi3_35_25_admin_guide.pdf.

You could do something similar with ESX 3.0.x but that was removed with ESX 3.5.

With ESX 3.5 you can create individual users, but you can’t grant permissions to specific VM’s without VirtualCenter.

  1. Once you have completed the permissions side of things start your favourite web browser and browse to your VC or ESX server web interface by using https://yourservername/ui

clip_image002

  1. Log into the web interface using your own Administrator account details, we will use this to create the link which you will be providing to the end user.
  1. clip_image004

    Use the navigation bar (blue area) on the left hand side of the screen to navigate to and click on the Virtual Machine you wish to give access to

  1. clip_image006

    Click the “Generate Remote Console URL” on the right hand side of the screen

  1. clip_image008

    Use this form to customise what you would like the user to see.

  1. Once completed you can copy the link from the light blue area and send this to the user.

There is also a dedicated client for accessing machines on the VC/ESX servers which also works very well, this can be downloaded from the following area: http://www.ntpro.nl/blog/archives/170-The-games-have-begun.html

clip_image010

More Powershell

I have now updated my first powershell script, this enables you to open a pre-configured spreadsheet with graphs and fill in the cells needed to populate the graphs and produce a nice 2 minute report on the state of the infrastructure, this is currently customised to my particular clusters but can be easily modified…

For a copy of the spreadsheet drop me a mail or a comment on this post.

Get-VIServer yourservername

$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Open("C:\Resource.xls")
$Sheet = $Excel.WorkSheets.Item(2)

$intRow = 11
$colItems = Get-Datastore | Select-Object -property "Name","FreeSpaceMB","CapacityMB" | Sort-Object Name
$totalcapacity = 0

foreach ($objItem in $colItems)
{
    $Sheet.Cells.Item($intRow,2) = $objItem.Name
$used = $objItem.CapacityMB – $objItem.FreeSpaceMB
$Sheet.Cells.Item($intRow,3) = $used
$totalcapacity = $totalcapacity + $objItem.CapacityMB

$intRow = $intRow + 1

}
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(5,4) = $totalcapacity

$Sheet = $Excel.WorkSheets.Item(3)
$Sheet.Cells.Item(4,3) = "Done"
$Sheet = $Excel.WorkSheets.Item(1)

$intRow = 17
foreach ($objItem in $colItems)
{
    $Sheet.Cells.Item($intRow,2) = $objItem.Name
$Sheet.Cells.Item($intRow,3) = $objItem.CapacityMB

$intRow = $intRow + 1

}

$totalmem = 0
$cpumhz = 0
$totalcpu = 0

Get-VMHost | %{Get-View $_.ID} | %{
$esx = "" | select NumCpuCores, Hz, Memory
$esx.NumCpuCores = $_.Hardware.CpuInfo.NumCpuCores
$esx.Hz = $_.Hardware.CpuInfo.Hz
$esx.Memory = $_.Hardware.MemorySize
 
$totalmem = $totalmem + $esx.Memory
$cpumhz = $esx.numCpuCores * $esx.Hz
$totalcpu = $totalcpu + $cpumhz
}
$formatedmem = ($totalmem /1024) /1024
$formatedcpu = ($totalcpu /1000) /1000
 
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(6,4) = $formatedmem
$Sheet = $Excel.WorkSheets.Item(3)
$Sheet.Cells.Item(5,3) = "Done"
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(7,4) = $formatedcpu
$Sheet = $Excel.WorkSheets.Item(3)
$Sheet.Cells.Item(6,3) = "Done"

$Sheet = $Excel.WorkSheets.Item(2)
$colItems = Get-Stat -Entity (Get-ResourcePool -Name "Live") -Stat cpu.usagemhz.average -MaxSamples 1 -Realtime
foreach ($objItem in $colItems)
{
    $Sheet.Cells.Item(4,4) = $objItem.Value
}

$Sheet = $Excel.WorkSheets.Item(3)
$Sheet.Cells.Item(7,3) = "Done"
$Sheet = $Excel.WorkSheets.Item(2)

$colItems = Get-Stat -Entity (Get-ResourcePool -Name "Test") -Stat cpu.usagemhz.average -MaxSamples 1 -Realtime
foreach ($objItem in $colItems)
{
    $Sheet.Cells.Item(5,4) = $objItem.Value
}
$Sheet = $Excel.WorkSheets.Item(3)
$Sheet.Cells.Item(8,3) = "Done"
$Sheet = $Excel.WorkSheets.Item(2)
$colItems = Get-Stat -Entity (Get-ResourcePool -Name "Live") -Stat mem.active.average -MaxSamples 1 -Realtime
foreach ($objItem in $colItems)
{
    $promem = ($objItem.Value /1000)
$Sheet.Cells.Item(4,3) = $promem
}

$Sheet = $Excel.WorkSheets.Item(3)
$Sheet.Cells.Item(9,3) = "Done"
$Sheet = $Excel.WorkSheets.Item(2)
$colItems = Get-Stat -Entity (Get-ResourcePool -Name "Test") -Stat mem.active.average -MaxSamples 1 -Realtime
foreach ($objItem in $colItems)
{
    $nonpromem = ($objItem.Value /1000)
$Sheet.Cells.Item(5,3) = $nonpromem
}
$Sheet = $Excel.WorkSheets.Item(3)
$Sheet.Cells.Item(10,3) = "Done"
$Sheet.Cells.Item(13,3) = "Done"

My first Powershell

I have seen on many if the VMware followers forums a way to use Excel to send commands to the VI server to create machines, alter vlans etc.

I wanted a way to export information and could not find anyone doing this yet other than using the export-csv so I created the following script which will export all the information for all Virtual machines in your virtual center straight to excel ready for you to manipulate. 

Don't forget to change yourservername for your virtual center server.

Get-VIServer yourservername

$Excel = New-Object -Com Excel.Application
$Excel.visible = $True
$Excel = $Excel.Workbooks.Add(1)

$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = "Name"
$Sheet.Cells.Item(1,2) = "Power State"
$Sheet.Cells.Item(1,3) = "Description"
$Sheet.Cells.Item(1,4) = "Number of CPUs"
$Sheet.Cells.Item(1,5) = "Memory (MB)"

$WorkBook = $Sheet.UsedRange
$WorkBook.Font.Bold = $True

$intRow = 2
$colItems = Get-VM | Select-Object -property "Name","PowerState","Description","NumCPU","MemoryMB"

foreach ($objItem in $colItems) {
    $Sheet.Cells.Item($intRow,1) = $objItem.Name
           
    $powerstate = $objItem.PowerState
    If ($PowerState -eq 1) {$power = "Powerd On"}
        Else {$power = "Powerd Off"}
       
    $Sheet.Cells.Item($intRow,2) = $power
    $Sheet.Cells.Item($intRow,3) = $objItem.Description
    $Sheet.Cells.Item($intRow,4) = $objItem.NumCPU
    $Sheet.Cells.Item($intRow,5) = $objItem.MemoryMB

$intRow = $intRow + 1

}
$WorkBook.EntireColumn.AutoFit()
Clear

Virtualisation Congress

Virtualization.info, the leading virtualisation news and analysis site since 2003 has announced the launch of Virtualization Congress (http://www.virtualizationcongress.com), the world’s first vendor independent virtualisation event, bringing together the industry’s biggest selection of virtualisation players, from the recognized leaders to the newest start-ups.

The conference, to be held at London’s ExCel, 14th-16th October, 2008, presents an ideal opportunity for current and prospective users of virtualisation technologies to hear directly from the companies at the cutting edge of their development; at the same time, in the same place for the first time ever.

VMware Certified Design Expert

The VMware Certified Design Engineer certification will be available later this year. The certification involved taking several courses and exams, including:

  • Courses
    Install and Configure
    DSA
    Design course (currently under development)
  • Exam
    VCP on VI3
    Enterprise Exam (currently in private beta)
    Design Exam (currently under development)

Once all of this has been completed the candidate must present a defensible design to a panel of VMware Solution Architects for consideration. As you may guess, this is a certification specifically targeted for VMware partners that will be assisting VMware in design and deployment and is only intended for a relatively small audience. That being said, the Enterprise Exam, which has a number of live lab style questions, should be available to the public in the next few months and may become part of a mid-line certification between VCP on VI3 and VCDX. That is also under consideration.