VMware – Determining ownership of a virtual disk using PowerShell

Tuesday, 29. June 2010

So as you may have guessed, I work with VMware a bit in my employment. On top of that, I’ve tried to start using PowerShell to automate repetitive tasks that I run into. (In fact, one of the major points of the existence of this page is to give myself a location to store these findings in a place which I can find them later, and if someone else finds them useful, then great.)

Anyway, the problem I ran into today was that I had a VM on a datastore whose name did not match a VM in my vCenter inventory. How could I tell if these files were in use by a legitimate VM or just wasting space? I could right-click and ‘Edit Settings’ on hundreds of VM’s… or I could use Powershell.

so I started off by connecting to the vCenter server and getting an inventory of VM’s:


Connect-VIServer servername
$VM = Get-VM

Then I grabbed a list of disks which matched my criteria:

$Disks = $VM | Get-HardDisk | Where {$_.FileName -like '*web*' }

Then I did…

$Disks | Get-Member and saw that there are Name, FileName, and ParentID properties. By doing $Disks | Select Name, FileName, ParentID,  I now have the parent Id of the VM.

So how do I know which VM the parent ID field references?

$VM | Where {$_.Id -like 'parent id from previous select'}

… which returns ….


Name PowerState Num CPUs Memory (MB)
---- ---------- -------- -----------
WebSrv1 PoweredOn 4 4096

Is there an easier way to do this? Probably, and I already have a couple of ideas. If I can get them working and cleaned up, I’ll post them here.

VMware Certified Professional (vSphere 4)

Sunday, 15. November 2009

So I took advantage of VMware’s VCP upgrade offer and have successfully passed the VMware Certified Professional exam for vSphere 4.

Normally VMware requires that a candidate complete an authorized training course in order to attain VCP certification, however, through the end of the year they are allowing current VCP’s on Virtual Infrastructure 3 to upgrade by successfully passing the vSphere 4 exam.  This is great for those of us who may not have the opprotunity to attend another class on our employer’s time and money.

VMware Certified Professional logo

VMware – Storage Migration (part 2)

Monday, 8. June 2009

In a previous post, I described a VMware Storage Migration task I was assigned and a quick run-down of the capability of the Storage VMotion feature.  Now, I’ll go into more detail about an awesome little tool that could make the process much easier.

The tool is called ‘SVMotion‘ and it is a plug-in to the Virtual Infrastructure client that you may already be using to administer your hosts and guest machines.  Once installed, it adds the ‘Migrate Storage’ option to the right-click menu of your VM’s.  When you select it, you will be presented with a window showing a list of datastores and the ones that the VM and its disks are on.

From here, you can drag the VM and its disks from their source datastore to the destination datastore.  Once you click ok, you’ll see a new ‘Relocate Virtual Machine Storage’ task that will show the migrations progress.

There’s a couple things I’ve learned from my use of this plug-in:

     1.  You have the move the actual virtual machine files as part of the migration whether you want to or not.  This is a Storage VMotion requirement.  If you like where the virtual machine files reside, move them with the disk and then move them back after.

     2.  This item appears to be a quirk of the plugin.  Say you have a VM with multiple disks but only want to move the virtual machine files and the first disk.  When you drag the VM to the destination datastore and click ok (having left the remaining disks in their original location), the plug-in attempts to move all VM files to the destination.  If you have the space, it will begin; if you dont, it will immediately return an error.

Overall, this plug-in is very nice and the price is right (free!).  It’s certainly much more convenient to use the GUI to initiate the Storage VMotion whenever you can.

VMware – Storage Migration (part 1)

Monday, 1. June 2009

Recently, I was tasked with migrating our entire VMware implementation to a new storage array.  Essentially, we are replacing our current SAN with one that is claimed to be bigger, better, and faster.

That sounds great, but how do you move 35 TB of data belonging to 800 VM’s with a minimal impact?  Storage VMotion may be what you’re looking for.

Storage VMotion can be a really useful tool.  Essentially, it can let you move a VM from one datastore to another while the VM is powered on, much like how a standard VMotion can let you live-migrate between hosts.

There are several considerations to keep in mind when preparing for a Storage VMotion.  A more complete list can be found here, but the more common ones we ran into were:

     –  Virtual machines with snapshots cannot be migrated using Storage VMotion.
     –  Virtual machine disks must be in persistent mode or be raw device maps.

The first one should be fairly obvious: you must delete any snapshots before performing an online Storage VMotion.

The second has to do with the disk “mode”.  You can research more about the different mode options but essentially the virtual disk must be able to be snapshotted (i.e. not “independent”) and the changes must be persistent (i.e. not discarded when the VM is powered off or a snapshot is deleted).  This is a requirement as the snapshot functionality is used by the Storage VMotion process.  If you have disks that may be marked as independent, you can plan to power down the machine and change this setting for the duration of the migration, or just migrate it while its off.

There are few different ways to perform a Storage VMotion which I’ll describe in a future post.

VMware Certified Professional

Monday, 1. December 2008

Several months ago, my employer brought in VMware to provide the Fastrack course covering VI3.  Along with the course, each attendee was given a voucher code to take the VMware Certified Professional (VCP) course.  After procrastinating for several months, and the voucher expiration nearing, I finally buckled down and started studying.

I scored a total of 98/100, while 70 is required to pass.

The Fastrack course is a lot of material.  For that entire work week, I spent 8+ hours a day in class, and the class could have been twice as long and still a challenge.

I’m sure this will be the last test of the year, but I am scheduled for a week of training on Microsoft’s System Center Configuration Manager product in January and there is an associated certification test for that product as well. 😉

VMware Certified Professional