Category Archives: PowerShell

VI Toolkit Webinar by Carter Shanklin

For those who haven’t had much exposure to the Powershell Toolkit and what it can do, there is a recording of a webinar presented by the Carter Shanklin at this link. It is pretty basic and intended for those with little or no exposure to the toolkit.

If you’ve ever wondered what it is or why you might want to use it (like disconnecting the CD from 45 or 50 VMs so you can VMotion them without having to deal with the right-click – pick-from-the-pop-up-menu process manually 45-50 times) then you might want to check this out.

More recorded webcasts are available on : http://www.vmware.com/a/webcasts/recorded/

Original Source and great site: here

Exporting Virtual Infrastructure Information to MS Word

The below is a script that will export various information into Microsoft Word using PowerShell and the VI Toolkit, this is completely risk free and does not alter anything, just feed it your VI server name and sit back, it can also be used as a scheduled task and even set to email you a word attachment.

It even throws in a few graphs and pie charts for good measure, almost all information can be sent to the functions for you to expand on the report easily.

Comments are welcome, the good the bad and the ugly !

Usage: report.ps1 YOURVISERVER

See below or download here:

Reporting Script

Getting Started with the VI Toolkit

I have become a big fan of the Virtual Infrastructure (VI) Toolkit over the last month and it has really helped me learn PowerShell which I knew I would have to learn sooner or later but kept putting off.

I would now like to spread the word and help out those of you wondering what the hype is all about by telling you how to get started.

Do I need to install the VI toolkit on the VI server ?

No, Definitely not, this can be installed on your workstation and can be used to hook into the Virtual Infrastructure, nothing additional will need to be loaded onto the VI server.

What you will need

Download the following and install them in order:

  • .Net framework 2.0 (if not already installed)

This is a Next, Next jobbie until completed.

This is also a Next, Next jobbie until completed.

Just to make a change this is a Next Next

That gets the basics but what you also may want to install is the following:

Once these have all been installed you are nearly ready.

From your desktop start the VI toolkit via the newly created shortcut or choose it from the Start Menu if you prefer, once started type the following and press enter:

Set-ExecutionPolicy RemoteSigned

You are now all set to start with PowerShell and the VI toolkit, lets do a simple task just to get you started…

From within the Powershell window now open connect to your Virtual Infrastructure server by using the following command or as you are now using powershell they are know as cmdlets.

Connect-VIServer YourServername

Obviously replace YourServerName with you VI Server.  Once connected you will be able to start issuing commands to the session to retrieve information, try the following simple cmdlet and press enter:

Get-VM

You will now see a list of all Virtual Machines.

And so it begins, this is just a simple cmdlet which will get you hooked from the start, issue the following command to list the other VI Toolkit cmdlets:

Get-VICommand

This should list enough for you to get started, now you can explore PowerShell and the VI Toolkit, for quick examples of what can be done take a look at the VMware examples here:

Managing VMware with PowerShell FAQ

Now there will be no looking back, welcome to the Jedi !

Powershell: Is Microsoft Word Installed ?

A quick script to check if Microsoft Word is Installed….

if ((dir  REGISTRY::HKEY_CLASSES_ROOT\Word.Application) -eq $Null){
       Write-Host "Microsoft Word not installed"
}
Else
{
       Write-Host "Microsoft Word Detected"
}

VMware Powershell Competition

I was wondering whether to enter the VMware Powershell competition or not, Looking at the prizes its a no brainer, how cool would it be to go to Vegas for VMworld 2008 ?!, but as you can see from my scripts on this site so far, they are no prize winners.  This is mainly because I am still relatively new to Powershell and still trying to grasp some of the concepts.

So anyway, I thought, what better way to grasp the concepts than to work towards something, so I have decided to work on my script and see how it goes, if it turns out ok then I may enter the comp just for the fun of it, although I’m sure there will be some master PS creators writing some amazing stuff.

So what am I working on ?

I’m working on something that will certainly be quite useful for myself and hopefully others… A VMware reporting script.

This will basically pull out all the config and details of things like your VMs, Hosts, Datastores, Clusters, Networks etc and put them directly into a nicely formatted Word document, I may even through in a few graphs for good measure to show top 10 Utilised VM’s and hosts, maybee a few pie charts to show how much room is left on the datastores ?!

If you think this is a good idea please let me know, just so I know I am not wasting my time ! and if you can think of anything else to put in there also please let me know – all ideas appreciated.

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