PowerCLI: How many HBA’s ?
Feb 9th
I needed a quick one-liner today to help me find out how many HBA’s my hosts had, the following one-liner needs no more introduction:
Get-VMHost | Select Name, @{N="FibreHBAs";E={($_ | Get-VMHostHba | Where { $_.Type -eq "FibreChannel"} | Measure-Object).Count}} | Out-GridView
Output:
LucD-2 here to help PowerShell self evolve
Feb 8th
For the PowerCLI lovers out there you may want to check out the recent Get-Scripting Podcast.
This month Jonathan and I have interviewed the master of PowerCLI himself, Luc Dekens or LucD on the forums and LucD22 on twitter.
Anyone who has ever visited the PowerCLI forums will know who Luc is, he also has an amazing blog with great walkthroughs on some of the more complicated PowerCLI areas including the SDK, events and alarms.
The rumour is that Luc is actually the next version of a terminator robot, here to help PowerShell self evolve, if you are interested in PowerCLI or automating VMware then please download episode 15 of the Get-Scripting podcast here:
http://get-scripting.blogspot.com/2010/02/get-scripting-podcast-episode-15-luc.html
Automated VM provisioning
Feb 8th
The use cases for PowerCLI and automation continue to amaze me, a couple of nice use cases I have seen recently involve automating the deployment of VM’s for various reasons.
The first reason, performance, what happens when a VM which is sat there for most of the year suddenly becomes busy and doesn’t have enough resources to satisfy whatever service it is trying to provide, do you add more ram, more CPU, what happens when you get to the maximum 8 CPU’s and the maximum vSphere VM memory of 255GB, do you then deploy a second VM and a third etc etc
Take this scenario into consideration:
You work in the UK for a county wide radio station, most of the time your virtualised cluster of web servers is sat there doing nothing, serving the odd hit now and again…but then it snows !
As we know, the UK can not handle snow at the best of times, the country grinds to a halt, the only means of knowing if your children’s school is closed is to check the local radio station’s website….enter our problem.
As you are also snowed in and unable to make it to the office you are unable to build the VM’s and add them to the cluster to allow the existing VMs which are now stuck on 100% CPU usage whilst you dig your car out.
Wouldn’t it be nice if we could have an automated response to this ? I held aloft my sword and said “With the power of CLI” (He-Man fans will get this).
I have two methods for this, the first one is a great script and the second is a bit of fun to show exactly how powerful PowerShell and PowerCLI can be. More >
PowerCLI: Changing a VM IP Address with Invoke-VMScript
Feb 5th
One of the cmdlets that has been much improved in the recent version of PowerCLU 4 U1 is the Invoke-VMScript cmdlet,
This cmdlet runs a script or command inside the guest OS of each of the specified virtual machines. To run Invoke-VMScript, the user must have read access to the folder containing the virtual machine and a Virtual Machine.Interaction.Console Interaction privilege.
The virtual machines must be powered on and have PowerShell and VMware Tools installed.
Network connectivity to the ESX system hosting the virtual machine on port 902 must be present.
You must also have both the Host and guest credentials available.
One question asked of me recently was “Is there a way to set the IP address of some windows virtual machines with PowerCI ?”.
So with the power of the invoke-cmdlet in the following example you can see how you can change the ip address by using the netsh command inside the VM.
As a note, you no longer need PowerShell inside the guest OS for this cmdlet to work, as you can see below I am calling a batch command, you can also use this cmdlet against *nix machines to run shell commands.
This of course can easily be adjusted to read all ip addresses from a csv file or text file and apply them to multiple virtual machines if needed.
Learn PowerCLI by video
Feb 4th
So you want to learn PowerCLI, if your not a book kinda person and haven’t purchased Hal Rottenberg’s great book, Managing VMware Infrastructure with Windows PowerShell then there is great news for you.
Trainsignal have let it slip that coming soon to a website near you will be….
Managing VMware vSphere with PowerCLI – Hal Rottenberg
- Video 1 Introduction to Power CLI
- Video 2 PowerShell Basics
- Video 3-1 PowerCLI Concepts – Part 1
- Video 3-2 PowerCLI Concepts – Part 2
- Video 4 Power CLI in the Real World
- Video 5 PowerCLI Cmdlet Deep Dives
So you not only get to learn PowerCLI but you also get to see the man behind the book, the man behind the podcast and the man behind the MVP – Hal himself.
PowerCLI: Working with events
Feb 1st
Today a question was asked of me, someone asked how to find out who had deleted a ResourcePool, now im not one to get anyone into trouble but I also cant resist a scripting challenge so here was the process I used to write the following one-liner:
Get-VIEvent | Where { $_.Gettype().Name -eq "ResourcePoolDestroyedEvent"} | Select CreatedTime, UserName, FullFormattedMessage
Ok, so we know that everything we do in the vSphere client produces an event so there must have been an event record, in this record we know that the person is recorded as we can easily create a test resource pool and delete it, this will allow us to test the information we need:
PowerCLI: Virtual Machine disk usage
Jan 27th
Recently I have had a few comments on an old post I wrote showing a one-liner to get the VM’s disk sizes for each VM, I was asked if there was a way to export this information into a CSV file.
The easy answer is yes but what you need to do is build up a container and then add each part of the information to the container, this is quite common practice in PowerShell, its a great technique where you can basically build and populate your own information and then just add to it, once you are completed you can then take your container and export it to whatever format you wish, for example:
The one-liner mentioned in my previous post simply outputted the data one VM at a time to the screen, whilst this was great for looking at the information, when we try and export it things start to go wrong !
The new script, below, may take up more lines but is far more efficient and adaptable.
Top 10 Virtualisation blogger
Jan 19th
All I can say is WOW ! (and Thank You)
I have been watching and voting in Eric’s polls since I started in virtualisation and never ever expected to see my name up there in lights, and in the top 10 too !
Thanks to everyone who voted for me, I really really appreciate it, this is exactly the reason I write my scripts and do not charge for them (despite pressure to do so) I could not believe it when I was told about this Sunday night, I think I am still dancing around in my head (not suitable in the office).
Congratulations to all other people mentioned in the top Virtualisation blogs and especially to Duncan of Yellow-Bricks.com for taking the Number 1 slot again, very well deserved too !
I really wish I had changed my twitter picture before hand though
PowerCLI on the iPhone
Jan 19th
Well not quite but the next best thing, I have been putting off getting an iPhone for a while now, I have always been a Windows mobile man starting back with one of the first windows mobile devices around, these were always one step ahead of the other phones when it came to the gadgets and things I wanted to do with a phone.
Recently I have been thinking about getting rid of my HTC Topaz (Diamond II) and succumbing to the iPhone geeks in the office, especially when I saw this…
Sapien Technologies are just about to release the latest version of their iPhone app called “iPowerShell 2.0”, this is a great cmdlet reference, much like my pdf but with all the help files and cmdlets in a nice easy accessible application, how cool is that ! More >
PowerCLI: Scripting ESXi
Jan 15th
As the service console is moved further away from the hypervisor, people are finding it harder to configure ESX in the same way as has been done in previous versions.
Moving forward the only way to do this really is by accessing ESXi through the API using scripting toolkits such as PowerCLI or the Perl toolkit.
There are two basic versions of ESXi “free” and “licensed”, the scripting toolkits are limited to read-only access for the free version of VMware ESXi. When the host is upgraded to vSphere Essentials, vSphere Essential Plus, vSphere Standard, vSphere Advanced, vSphere Enterprise, or vSphere Enterprise Plus these toolkits have write-access enabled and provide a scriptable method for managing ESXi hosts. More >






