Posts Tagged ‘powercli’

Clone-to-test: Part 2

In this post I present the first script. It took me quite a while, as I had to figure out how to do everything. I’m no rocket-scientist, so if I can figure it out, you all have hope too. I really do suggest getting your hands dirty in some code, powershell is pretty easy to pick up. :)

If you haven’t done so already, I would suggest reading Part 1. You may also want to check out the architecture of my isolated test environment, as the design is pretty closely linked with my particular requirements.
Read the rest of this entry »

Clone-to-test: Part 1

Well it’s taken me a while, but I’ve just completed the first part of my test environment migration process. So I thought I’d post up the design and architecture diagrams.

The idea is to provide a repeatable process for cloning batches of VM’s from the production network into my organization’s isolated vm-test environment. The cited use cases for this environment include Virtualization infrastructure change testing, VI development, VI product evaluation and Virtual Machine change test/verification. This series of scripts addresses the last requirement in an automated manner. Read the rest of this entry »

VMware Basic VM Performance as XML (Powershell)

Well continuing my recent foray into scripting, I wrote a small script to dump some basic stats about each VM into formatted XML.

The purpose is to get a basic idea of average use accross all our VM’s. We’re using this information as part of a virtual infrastructure review and redeployment. We have budget to replace aging ESX hardware and we’re taking the opportunity to tidy things up a bit.

The script is using the same framework as my dump-virtual-machine-info-as-xml script posted previously. I’ve grown quite fond of XML, although I’m sure I can definitely improve it…. for a start creating a proper schema.
Read the rest of this entry »

Dump Virtual Machine Info as XML (powershell)

Hi All,

I was recently asked to provide a comprehensive list of VM’s and their currently provisioned hardware. We have a need to duplicate this view in the future, so I decided to script it. My org also does charge-forward, so this dump of information is useful.

I used the script by Arne Fokkema “PowerCLI: Virtual Machine Disk (VMDK) info v2: Analyze data with Excel” as a base.

I initially tried to use the built-in XML export option, however the formatting wasn’t very nice, so I decided to build a custom schema and populate that instead. Using this approach allowed me to include all the detail I wanted, nested appropriately… for easy collation and searching later in excel.

So running through the script, this is how it works.

Firstly, like a good programmer, define the global variables.

#--- Parameters ----------------------------------------------------------------------------------------------
#XML Template
$XMLTemplateFile = "C:/tmp/VMachines_Template2.xml"
#Output XML File
$XMLOutput = "c:/tmp/VMachines.xml"
#Use Shortname?
$UseShortname = "True"
#Get Application details?
$GetAppdocInfo = "False"

Ignore the AppdocInfo flag…. that’s for another day 😉

Now, since we’re creating a custom XML output we need to define the template.

#Define the XML Template
$XMLTemplate = @'
... etc
'@
$XMLTemplate | Out-File $XMLTemplateFile -encoding UTF8

$XMLVMachines = New-Object XML
$XMLVMachines.load($XMLTemplateFile)
$XMLVMachine = @($XMLVMachines.VMachines.VMachine)[0]

The template is defined inline, written out to a temporary template file, then read back in as an array of XML objects (with only one object so far, the template). Once that’s done, we can populate the array by cloning the template and adding data.

Now we have a custom XML object to work with, we can begin collecting the required data. Read the rest of this entry »

The opinions expressed on this site are my own and not necessarily those of my employer.

All code, documentation etc is my own work and is licensed under Creative Commons and you are free to use it, at your own risk.

I assume no liability for code posted here, use it at your own risk and always sanity-check it in your environment.