Creating a Hyper-V VM Memory Report

I use Hyper-V to run my lab environment. Since I work at home I don’t have access to a “real” production network so I have to make do with a virtualized environment. Given budgetary constraints I also don’t have a lot of high end hardware with endless amount of RAM and storage. So I often run my virtual machines with a bare minimum of memory. Most of the time this isn’t a problem. Still, there are times when I need to quickly see how much memory I’m using up. I can use either the Get-VMMemory or Get-VM cmdlet.

The latter cmdlet includes a bit more detail.

All of the values are in bytes which I know I could convert to MB with a custom hashtable. But I don’t want to do that all the time so I created a command to get detailed virtual machine memory.

I’ve posted versions of this function over the last few years so you may have come across earlier iterations. The major changes in this version is that I’m calculating a utilization percent of memory demand vs assigned. I also added a switch to only show virtual machines with a Low memory status, since often that’s the most important thing I want to know.

Now I can easily get information for a single VM

Or multiple:

Clearly my SQL Server needs a little attention.

I hope you’ll try it out and let me know what you think.

VMDK to VHDX PDQ

I have a very old VMware ESXi server that has outlived its useful life. The hardware is at least 5 years old and my VMware license has expired. I can still bring up the server and see the virtual machines, but that’s about it. I still keep the box so I can run the PowerCLI cmdlets, at least in a limited fashion. However, there are a few virtual machines that I need to get at so I can move some applications and data to another Hyper-V virtual machine. Since I can’t get the VMware virtual machine running, I can at least convert the disk to a VHDX and bring it up in a new Hyper-V virtual machine.

I already have PowerCLI 6.0 and the Hyper-V cmdlets installed on my computer. My initial thought was to use the free Microsoft Virtual Machine Converter which you can download. But I ran into a number of issues using the GUI, primarily because not everything is in the same domain. But that doesn’t really matter because I didn’t really want to migrate the complete virtual machine, I just needed to bring up the old VM temporarily so I could migrate things off. Fortunately, there are a set of cmdlets that ship with Microsoft’s converter. Here’s what I did.

First, I needed to connect to my ESXi box using the PowerCLI cmdlets.

I need to get the disk files for a given virtual machine. One benefit of PowerCLI is that you can easily browse the datastore files.

I’ll need all of these files. But first I need to be able to access them from the file system. Fortunately, PowerCLI has a handly cmdlet for copying items from a datastore to the file system.

Once the files are copied I can begin the conversion. However, the Microsoft virtual machine converter cmdlets aren’t installed in an expected location so I’ll have to manually import them.

Once imported, I can use ConvertTo-MvmcVirtualHardDisk.

The conversion took about 20 minutes for a 40GB file. The converted file was 30GB for a dynamic hard disk. With the conversion complete, it is pretty easy to fire up a new Hyper-V virtual machine.

You’ll notice that I am using a complete path for the New-VM cmdlet. That’s because in my session I have both PowerCLI and Hyper-V cmdlets and they both have a New-VM cmdlet. Normally I wouldn’t have both running in the same session but since I do, I need to explicitly tell PowerShell which cmdlet to use.

And that’s about it. Once running I uninstalled the VMware Tools, installed the Hyper-V Integration Toolkit and let Windows detect everything else. This would require me re-activating Windows, but I’m hoping to migrate everything I need before that becomes an issue.

 

The Altaro PowerShell Hyper-V Cookbook

powershell-cookbook-ebook1 For awhile now I’ve been contributing to the Altaro Hyper-V blog. Many of my articles centered on managing Hyper-V with PowerShell. I’ve gone through my library of management tools and written an eBook around them. All of the PowerShell scripts and functions have been polished up a bit. The eBook briefly discusses how to you use each recipe. It is a cookbook after all.

All of the recipes have been tested, but even so you should test everything in a non-production environment. Every Hyper-V environment has its own quirks. Or you can use the recipes as jumping-off points for your own PowerShell and Hyper-V. When you download the eBook be sure to get the accompanying zip file of code samples.

Visit http://www.altaro.com/hyper-v/new-ebook-altaro-powershell-hyper-v-cookbook/ to learn more and download your free copy. I hope you’ll let me know what you think

InfoWorld: Automate Live VM Export

infoworldThis is kinda cool, but I got published in InfoWorld, in a roundabout manner. J. Peter Bruzzese writes a column for InfoWorld on enterprise Windows. His latest column is about exporting Hyper-V virtual machines using PowerShell. In Windows Server 2012 R2 (and Windows 8.1) you can export a virtual machine even while it is running. Peter wanted to demonstrate with a weekly and monthly scenario using PowerShell to export virtual machines to a new folder and also delete older versions. The end result would be a set of 4 weekly folders and 2 monthly folders. But he needed help with some of the PowerShell so I pulled together a script which is linked in the InfoWorld article.

The script I wrote is a bit more complicated than what Peter originally envisioned. Now, I doubt his goal could be accomplished with a one-liner. So since I needed to write a script, I took the time to make it robust with items such as error handling and parameter validation. I only wanted to develop the script once so why not be thorough?

As I as finishing up the script to Peter’s requirements, I realized this could also be tackled using a PowerShell workflow. One of the limitations in the original script is that it needs to run on the Hyper-V server. I didn’t include any provision for connecting to a remote server. I also recognized that exporting multiple virtual machines could be done in parallel. Although my original script allows the use of background jobs which is sort of like running in parallel. But I thought a workflow version might at least be educational. Here is the Export-MyVM workflow.

Most of the code is the same as the original script, although I removed the WhatIf parameter. You can’t use SupportsShouldProcess in a workflow and I didn’t have the time to fully write my own. The only code that is really workflow specific is this:

Perhaps the biggest advantage is that with a workflow I get automatic support for background jobs and remoting. Now I can execute the workflow against the Hyper-V server.

And I could still create a PowerShell scheduled job on my computer to run this workflow.

By the way, I’m sure you are aware that there are plenty of Hyper-V backup products from companies like Altaro, Veeam and Unitrends (all of whom help support my blog). Some of them even have free versions of their products. So while you can use PowerShell to export VMs that doesn’t mean you should. Although I can see value for a quick and dirty backup. Ultimately, I suppose it is a good thing to have options.

Enjoy.

Mini Hyper-V Benchmarks

I’ve received a lot of interest in my mini Hyper-V project. I’m still running preview bits of Microsoft Hyper-V Server 2012 R2. Once final bits are released I’ll do a clean re-install. But until then I’ve been using it running about 4 virtual machines without a hiccup. I was getting some questions about benchmarks so I thought I’d post what information I could.

Part of the challenge in using a benchmarking tool is that I’m running Server Core so most tools won’t run. I was able to install Dacris Benchmarks on the server and run some benchmarks. I didn’t bother with the video tests and not all features of the tool work on Server Core. But I was able to gather enough information if you are interested.

Overall, it looks like a pretty good system for what I need.

dacris-summary

I hope it’s obvious this isn’t a production-level server for a datacenter. But for testing and lab work it is more than adequate. and personally, the portable form factor was the driving force. Dacris Benchmarks confirms my theory.

dacris-grade

Here are the results from some of the advanced tests.
Memory Transfer Rate for Large Blocks
largblocks

Memory Transfer Rate for Small Blocks
smallblocks

CPU Parallel Scaling
parallel

CPU Pi Calculation
pi

I also decided to grab system information with MSINFO32.EXE.

chi-hvr2-si

While not a benchmark, some of you may be interested in the nitty-gritty. You can also download a zip file with the complete NFO file.

Finally, if you missed any of the earlier articles on my project here they are:

Part 1: Intro and Specs
Part 2: Hardware Build
Part 3: Setup
Part 4: Operating System

I expect just about anywhere I will be presenting or training I’ll have this with me so please feel free to find me if you want a closer look.