During our presentation at the Dutch VMUG Event 2011, Alan and myself showed how several entries of the Top 10 vSphere 5 Features session could be automated with the help of PowerCLI. In the session we showed several demos.
This post is the first in a series, that will publish and document most of the scripts we used for the demos.
On the first position in the Top 10 we have Storage DRS. This feature brings intelligent placement of VMs and storage load balancing based on space usage and IO metrics. See part 4, part 5 and part 6 in Cormac‘s excellent series on vSphere 5 Storage Features.
Continue reading vSphere 5 Top 10 – Storage DRS
Buried in the massive amount of new features introduced with vSphere 5 there are several new API methods on the HostStorageSystem managed object.
Two of these API methods will allow you to automate the new Attach/Detach LUN feature from the vSphere Client. It concerns the AttachScsiLun and DetachScsiLun methods. Until this new feature is available natively in PowerCLI, you can use the following functions.
Continue reading LUN juggling in vSphere 5
After the Cloud Infrastructure Launch Forum event from July 12th 2011, it seemed that the new licensing model attracted more blog posts and tweets than the 140 new features in vSphere 5.
As one could imagine, one of the most heard questions was, what will I need to pay in the new licensing model. As a pro-active measure, I decided to write a short script that would tell me what vRAM entitlement my current vSphere 4 licenses would offer me.
Update August 4th 2011 08:30: VMware updated the vRAM calculation specifications. See the VMware vSphere™ 5.0 Licensing, Pricing and Packaging White Paper.
Update July 13th 2011 14:45: Apparently you have a vRAM pool per license type. I updated the script.
It happens quite often that you launch a PowerCLI cmdlet or a call to a SDK method or a script and that you get a rather cryptic message that something went wrong. One source of information to find out what went wrong are the vCenter’s vpxd log or the ESX(i) server’s hostd log.
But these logs are flooded with messages and it’s often quite hard to find the messages that relate to your task.
When running against a vCenter Server you can set the vCenter’s Logging Options to “Verbose” or “Trivia“. That produces more information in the logs but that often also makes it harder to find/extract the information that belongs to your task. And who has never forgotten to set the the Logging Options back to their original state when done with debugging ?
To make life a bit easier, I wrote a function that automates the above steps. I expanded on a function that I was using privately, and made it more general. This function allows you to retrieve the log entries for one specific or all recent task. The function also allows you to pass a cmdlet, or even a complete script, run the script in an elevated Logging Options mode and returns the task-related log entries.
A useful property that is obviously missing from the Get-Folder cmdlet, is the path of the folder. In the PowerCLI Community there are regularly threads that ask for this kind of information. Most of the time it concerns scripts to export/import folder structures or scripts to migrate vCenters.
Another property that is obviously missing, is the indication if a specific folder is a so-called “blue” or “yellow” folder.
To solve this problem once and for all, I wrote this short function, called Get-FolderPath, that will return you both of these properties.
The VMTN Communities have always been a useful source of inspiration for writing scripts. This week, for example, there was an intriguing question raised in the Onyx Community. The user wanted to know if it was possible to monitor changes in the vSphere environment in real time.
As far as I know there is no API in the vSphere SDK to do real time monitoring. But the EventHistoryCollector can deliver something that I prefer to call nearly real time monitoring. The following script is a very basic function, written primarily to show that this principle of nearly real time monitoring works. The function displays some selected properties of each event it sees.
Continue reading Nearly real time monitoring
One of the announcements during VMworld 2010 in San Francisco that perhaps got a bit obscured by the other “big” announcements, was the release of Onyx 2.0. For those of you that hadn’t heard of Project Onyx before, this nifty little tool captures all SOAP traffic that is passed between your vSphere client or PowerCLI session and the vCenter or ESX(i) server to which you are connected.
And that’s not all, the Onyx program will translate the captured SOAP traffic into PowerShell code. This allows you to see which vSphere APIs are used and how parameter objects for these methods are constructed.
Update September 16th 2010: the Onyx Development Team has just released a new build (2.0.3910.32223) that fixes some issues when using Onyx with the PowerCLI client. Congratulations to the Onyx Development Team for this quick resolution of the problem !
One of the new features that came with vSphere 4.1 was the ability to use Active Directory Authentication on ESX(i) servers for permissions, console access and ssh access.This is a great feature that you will probably want to activate on all your ESX(i) servers.
Unfortunately this new feature is not available in PowerCLI 4.1. That means you can’t set this up in your configuration scripts through a PowerCLI cmdlet. In most such cases you can fall back on one of the SDK APIs to bypass this lack of a cmdlet. But unfortunately the new “managers”, of which HostActiveDirectoryAuthentication is one, are not available in the VMware.Vim assembly either.
Rob raised this in a recent PowerCLI Community thread. Yasen, one of the PowerCLI Dev Team members, provided a bypass. To make this bypass a bit more accessible, I decided to roll it up in a PowerShell function.
Continue reading Script vSphere 4.1 AD Authentication
Triggered by a recent post, see get-virtualportgroup, in the PowerCLI Community, I had a closer look at the Get-VirtualPortgroup cmdlet.
This cmdlet returns a VMware.VimAutomation.Types.Host.VirtualPortGroup object, which contains a very useful property called Ports. In that property it lists all the guests that are connected to a port on the portgroup. That would be the solution to find unused portgroups, I thought. But while the vSphere Client also shows powered off guests that are connected, the Port property returned by the Get-VirtualPortgroup cmdlet doesn’t. 🙁
So the question at hand required a bit more scripting than I originally thought.
Continue reading Find unused portgroups in a cluster
Today there was quite a bit of activity on Twitter following Jason Boche‘s blog post titled VMware Update Manager Becomes Self-Aware.
The problem Jason discovered was that the VUM skipped the guests which are hosting the VUM server and the vCenter server. As a consequence you can not select a cluster, select “remediate” and go out for lunch anymore. The resolution was a rather cumbersome and error prone manual procedure.
But of course PowerCLI can help the human vSphere administrator 😉
Continue reading Counter the self-aware VUM