Virtualization Pro

Sep 27 2009   7:00PM GMT

The vSphere API is not just for programmers

Halr9000 Hal Rottenberg Profile: Halr9000

The topic of the VMworld 2009 session which Luc Dekens and I gave recently was how to take PowerCLI to the next level. I’ll explain that premise for a bit in this post for those who may not have been able to make it to the session (or the show, for that matter).

PowerCLI has a lot of functionality built in. As of this writing, there are 165 cmdlets that let you do a wide range of tasks such as starting virtual machines or creating virtual switches. Cmdlets are great because they are high-level, task-based, and their usage is mostly consistent across all domains, whether you are talking about virtualization or managing your mail servers.

Here’s a PowerShell command which will display all of the various types of objects which you can manipulate with PowerCLI.

As you can see from the output, the scope is pretty broad:

PS > Get-VICommand | sort noun | group noun | Format-Wide name

CDDrive Cluster

CustomField Datacenter

Datastore DrsRule

FloppyDrive Folder

HardDisk Inventory

Log LogType

NetworkAdapter OSCustomizationSpec

ResourcePool ScsiLun

ScsiLunPath Snapshot

Stat StatInterval

StatType Task

Template Tools

VICredentialStoreItem VIEvent

View VIObjectByVIView

VirtualPortGroup VirtualSwitch

VIServer VIToolkitConfiguration

VIToolkitVersion VM

VMGuest VMHost

VMHostAccount VMHostAdvancedConfiguration

VMHostDiagnosticPartition VMHostFirewallDefaultPolicy

VMHostFirewallException VMHostFirmware

VMHostModule VMHostNetwork

VMHostNetworkAdapter VMHostNtpServer

VMHostProfile VMHostProfileCompliance

VMHostService VMHostSnmp

VMHostStartPolicy VMHostStorage

VMHostSysLogServer VMResourceConfiguration

VMScript VMStartPolicy

Even so, the vSphere application programming interface (API) is so large that there are still an astonishing number of things which are not handled by the existing set of cmdlets. Sure, VMware continues to work on this toolkit and to expand its capabilities — the rumor is that over 200 cmdlets will ship with version 4.1 — but the team that works on PowerShell is limited by time and resources, so it’s doubtful that they’ll reach parity with the API anytime soon.

Luckily, there is a release valve — a hidden door, if you like, that will let you go behind the scenes to go where no VMware Infrastructure (oops, meant to say vSphere) admin has gone before. The name of that hidden door is the Get-View cmdlet. “Get” in the PowerShell world just means to retrieve an object from somewhere. But what is it really that you are getting? You are getting an unfiltered view of the “managed objects” which make up the heart of the API. Once you have that view, you can do anything you want which the underlying API supports.

Here is a quick example of the sort of cool things you can see with Get-View:

PS > $h = Get-VMHost | Get-View

PS > $h.Summary.Config.Product

Name : VMware ESX

FullName : VMware ESX 4.0.0 build-164009

Vendor : VMware, Inc.

Version : 4.0.0

Build : 164009

LocaleVersion : INTL

LocaleBuild : 000

OsType : vmnix-x86

ProductLineId : esx

ApiType : HostAgent

ApiVersion : 4.0

InstanceUuid :

LicenseProductName : VMware ESX Server

LicenseProductVersion : 4.0

DynamicType :

DynamicProperty :

And now you know how to write a script to make sure your host servers are all on the same patch level!

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: