Home > Blogs > VMware PowerCLI Blog > Monthly Archives: June 2009

Monthly Archives: June 2009

Stuff worth checking out.

There’s been a lot of PowerCLI-related stuff going on lately that’s worth checking out.

vProfiles and more.

Monsieur Alan Renouf has been hard at work lately and had turned out some really amazing stuff. The first is what he calls vProfiles. From the looks of it, vProfiles is still in a fairly early stage, but right now it is able to duplicate virtual switch and portgroup information between two ESX hosts via a graphical interface. Alan also posted a video showing the script in action.

vProfiles from Alan Renouf on Vimeo.

This looks really exciting and Alan is looking to improve its functionality over time to include more than just networking. Chances are it’s also very easy to extend this to apply a configuration to an entire cluster rather than just a single host, and I think we’ll see that ability pop up in the near future.

Another really cool script Alan wrote recently was SnapReminder. SnapReminder will automatically generate an email nag to anyone who has left a snapshot sitting around too long. The most notable thing about SnapMinder in my opinion is that it blends together information from VMware vSphere and Active Directory in a completely seamless way. As if that weren’t enough there are some other great scripts Alan wrote between these two that are also worth checking out.

vWire.

vWire is a new product from the people who brought us Tripwire (some of us feel old when we think about the first time we used Tripwire.) Anyway, the vWire team has taken some of this knowhow and have produced a tool to monitor and analyze your VMware environment, and keep it running smoothly.

vWire has some videos that can help you get started, particularly their getting started video. vWire also offers some really powerful, SQL-based searching capabilities. You may be wondering what this has to do with PowerCLI, but vWire supports script actions, which let you run PowerCLI scripts to do things like display log files or change ESX host configuration. You can see all their content in their content library.

vWire lists for $295 per CPU + Support, and if you’ve got more than a very basic Virtual Infrastructure vWire might a great addition to your portfolio of management tools.

Lastly, but not leastly, PowerWF Studio.

I blogged about PowerWF Studio a while back on the VMware VIX blog, but since then they have also released support for PowerCLI. PowerWF Studio is a graphical workflow builder built on Windows Workflow Foundation

There are a lot of great PowerWF videos on YouTube but one of the best ones right now shows you you can take a PowerShell script you have already written and embed it in a workflow. If you’ve ever visited our communities, or read PowerCLI blogs you know that there are hundreds of really useful scripts out there that solve myriads of problems. With PowerWF it’s now easy to embed these in workflows.

As PowerWF continues to add more actions and adds the ability to talk to more and more software products it should be a tool worth watching.

Finding and fixing VMs connected to missing port groups.

Yesterday someone took the liberty of upgrading one of my ESX servers that I use to run a virtual vSphere lab. Fortunately he was kind enough to preserve all of the VMs, and they were restored and re-registered after the upgrade.

There was one detail that he didn’t notice, which was that my virtual vSphere lab VMs were all connected to an internal network called “Internal”. When I got in today my lab didn’t work at all because there was no networking between vCenter and the ESX hosts or their shared storage. The network cards all said they were attached to the “Internal” network, but there was no Internal network! Fortunately this was pretty easy to fix with PowerCLI.

First, let’s look at a script that will identify any VM that is connected to a non-existent network:

# Search for VMs that are connected to a non-existent portgroup.
$pgNames = Get-VirtualPortGroup | Foreach { $_.Name }
Get-VM | Where { $_ | Get-NetworkAdapter | Where { $pgNames -notcontains $_.NetworkName } }

This code starts by getting a list of all portgroup names. Then it goes through all VMs and identifies any VM that has at least one network adapter connected to a non-existent portgroup. Note that this assumes we are connected directly to ESX. If you need to use something like this against vCenter you should do it on a host-by-host basis. Anyway, when I ran it here was the result:

shot1

These are all the VMs of my virtual lab. Now let’s go about fixing the problem. First, creating the Internal virtual switch and portgroup are pretty easy:

# Create the missing switch and portgroup.
New-VirtualSwitch -Name Internal
Get-VirtualSwitch -Name Internal | New-VirtualPortGroup -Name Internal

Now the portgroup exists but there is one last problem: the VMs are not actually connected to the portgroup. Again, pretty easy to fix.

# The guests that were powered on will still be disconnected, so connect them.
Get-VM | Get-NetworkAdapter | Where { $_.NetworkName -eq "Internal" } |
  Set-NetworkAdapter -Connected:$true -Confirm:$false

With that, everything is back to normal.

Listing RDMs and adding NFS datastores all over the place.

This post is going to cover some useful and popular recent content seen on our community. If you haven’t seen our community, it really is the best way to learn about PowerCLI and start getting automated. Today I’m going to touch on two topics. First, I’ll cover a script to list all RDM information, then give a script that will let you add NFS datastores to all your hosts in one shot.

Listing RDM Information

If you’re wondering what an RDM is or why you might use it, check out Rich Brambley’s blog for a really good explanation. Long story short is that RDMs are often used because you need to use Microsoft Cluster Services, or if you want to take advantages of features of your storage hardware.

In PowerCLI, RDMs will show up when you run the Get-HardDisk cmdlet. Specifically they will have a type of either “rawPhysical” or “rawVirtual”, depending on the type of RDM. However, they won’t have things like the SCSI LUN, which you may find very useful to report on. If you need this information, Luc Dekens has the script you’re looking for. It will list all RDMs on all VMs, along with their size, SCSI device, etc.

Adding NFS Datastores to Multiple vCenter or ESX Hosts

If you have more than a few hosts you probably have shared storage, this is what enables a lot of vSphere’s great features like vMotion. For this to work smoothly, however, you need that storage to be available on all your hosts in a consistent way, and this can turn in to quite a challenge as your environment grows.

Not long ago a question was asked about how to automate adding datastores across multiple vCenters. Not surprisingly, Luc also suggested an answer, and it’s a pretty good one. However I want to offer a slightly different answer. The first thing we should do is define all our NFS mapping information in a CSV file, like this:

VCName

DatastoreName

NfsHost

NfsExport

192.168.1.1

NFS1

10.24.1.1

/share

192.168.1.1

NFS2

10.24.1.2

/share

192.168.1.1

NFS3

10.24.1.3

/export

192.168.1.2

NFS1

10.24.1.1

/share

192.168.1.2

NFS2

10.24.1.2

/share

192.168.1.2

NFS3

10.24.1.3

/export

192.168.1.3

NFS1

10.24.1.1

/share

192.168.1.3

NFS2

10.24.1.2

/share

192.168.1.3

NFS3

10.24.1.3

/export

One great feature of PowerShell is its Import-Csv cmdlet, which will turn lines from a CSV file into objects that you can access just like any other object. My variation on Luc’s solution is to use the Group-Object cmdlet and group these entries by the VCName property. This way, if you’re adding multiple datastores to a single VC, you only have to log in once. Here’s my full solution to the problem, which assumes that you’ve saved your data into a file called nfs.csv.

Import-Csv nfs.csv | Group VCName | Foreach {
 Connect-VIServer -Server $_.Name
 Foreach ($entry in $_.Group) {
  Get-VMHost | New-Datastore -Nfs -Name $entry.DatastoreName `
   -Path $entry.NfsExport -NfsHost $entry.NfsHost
 }
}

Closing Thought

Be sure to check out our community, it really is the most valuable source of information for automating with PowerCLI.

VMworld 2008 “Managing VMware With PowerShell” session now available free.

Last year at VMworld I gave a talk about PowerCLI (back then it was VI Toolkit for Windows) which was attended by about 650 people. No eggs were thrown so I have to guess it was an ok session. Eric Siebert agreed and recommended that it be made freely available. Well, now it is, and you can view the session using your VMworld account.

The session has a high-level overview of PowerCLI, samples and a couple of pretty cool demos courtesy of my colleague Andrey Anastasov and Mr. PowerGUI, Dmitry Sotnikov of Quest Software. If you’re hoping to get your vSphere environment more automated, it’s worth checking out.

June 2009 PowerCLI Webinar: The aftermath.

In case you missed our June 2009 PowerCLI webinar, a replay is available. In this webinar I covered some tips for getting stats out of vSphere, viewing log data and advanced configuration.

I’ve made all the scripts used in this presentation available for download. Bonus: There is also a sample in there that shows scheduling a nightly report.

You can also see the presentation on slideshare.

June 2009 PowerCLI Webinar

View more presentations from vmwarecarter.

Other important links mentioned in the webinar were:

Enjoy