Category Archives: Hyper-V

Standardize your Hosts: Simplify your Life

For several years I have been speaking and writing about desktop deployment to standardize your client system environment.  What about your servers? What about your hypervisors? 

A couple of years ago VMware introduced Host Profiles into vCenter Server which allow you to take all of the settings from one host and then apply them to all of your other hosts.  Nice… but unfortunately it is a feature only of the Enterprise Plus SKU of the product. 

Microsoft has similar functionality with System Center 2012 R2, which is a real godsend for larger organizations.  But what about the smaller companies?  What about companies that have not completely implemented the whole System Center suite of tools?  Are they doomed to having multiple hypervisor configurations?  No… that’s what PowerShell is for!

Super-Shell!Okay, PowerShell is for a lot of things; in fact it is for just about everything, depending on how well you want to use it.  However with the help of my friend and fellow Microsoft MVP Sean Kearney I have put together a list of cmdlets that will do the job for you.

Firstly we should recognize that there are infinitely more settings to configure in VMware vSphere than there are in Microsoft’s Hyper-V; hundreds of settings, any of which can prevent critical functionality from performing properly.  There are certainly issues that need to be properly configured in Hyper-V, but not nearly as many.  With that being said, it is still important to standardize your Hyper-V hosts, if for no other reason than to simplify management, but also to ensure failover readiness and more.

For the purpose of this article I am going to assume a directory on all hosts called c:\Profile.  You can really name the directory anything you like.  In fact none of the file names have to be what I call them, as long as you remember what you use.

Hyper-VOh, and before you ask, this article applies to the full GUI version of Windows… and MinShell… and Server Core… and yes, even Hyper-V Server!

In PowerShell there is a simple cmdlet: Get-VMHost |fl.  This will show you all of the host settings.  The fl gets the full list, instead of the basic information.

If you are simply trying to collect the host settings for the purpose of documentation, you can export this information to a .csv (comma separated value) file that can be read in a text editor or, more importantly, in Microsoft Office Excel.  That cmdlet would be Get-VMHost |Export-CSV c:\Profile\HostSettings.csv.

PowerShellWhile this is helpful for documentation purposes, in order to actually work with the information we are going to export it to a .xml (Extended Markup Language) file.  It will be harder for us to read, but easier for the computer to work with.  The cmdlet to do that is Get-VMHost |Export-CLIXML c:\Profile\HostSettings.xml.

Now that we have collected the information, we can start applying the information to other hosts.  The corollary to any Get- cmdlet in PowerShell is a Set- cmdlet.  However the .xml file has some information in it that we would not want to apply to each host – hostname, for example.  So although we could theoretically apply each setting by hand (set-VMHost <parameter>) I have taken the liberty to write a script that would apply all of the information for you, based on the file we collected earlier:

$info=Import-CLIXML C:\Profile\HostSettings.xml

Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath
Set-VMHost –VirtualMachinePath $info.VirtualMachinePath
Set-VMHost –MacAddressMinimum $info.MacAddressMinimum
Set-VMHost –MacAddressMaximum $info.MacAddressMaximum
Set-VMHost –MaximumStorageMigrations $info.MaximumStorageMigrations
Set-VMHost -UseAnyNetworkForMigration $info.UseAnyNetworkForMigration
Set-VMHost -FibreChannelWwnn $info.FibreChannelWwnn
Set-VMHost -FibreChannelWwpnMaximum $info.FibreChannelWwpnMaximum
Set-VMHost -FibreChannelWwpnMinimum $info.FibreChannelWwpnMinimum
Set-VMHost -ResourceMeteringSaveInterval $info.ResourceMeteringSaveInterval
Set-VMHost -NumaSpanningEnabled $info.NumaSpanningEnabled
Set-VMHost -EnableEnhancedSessionMode $info.EnableEnhancedSessionMode

Let’s look at the format of this script.

1)  $info=Import-CLIXML C:\Profile\HostSettings.xml
What we are doing here is importing the .xml file that we created into a variable called $info.  Each piece of information in the XML file will be called using that variable.

Next let’s look at one of the Set-VMHost lines:

2) Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath
What we are doing here is taking one of the parameters – the default directory for new virtual hard disks – and setting it with the VirtualHardDiskPath parameter from the .xml file… because we imported that file into $info, that sub-variable is expressed as $info.VirtualHardDiskPath.  We will repeat that for each parameter.

So essentially for this script we are running the same cmdlet twelve times with different switches.  Can we put them together into a single line? Sure… it would look like this:

Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath –VirtualMachinePath $info.VirtualMachinePath –MacAddressMinimum $info.MacAddressMinimum –MacAddressMaximum $info.MacAddressMaximum –MaximumStorageMigrations $info.MaximumStorageMigrations -UseAnyNetworkForMigration $info.UseAnyNetworkForMigration -FibreChannelWwnn $info.FibreChannelWwnn -FibreChannelWwpnMaximum $info.FibreChannelWwpnMaximum -FibreChannelWwpnMinimum $info.FibreChannelWwpnMinimum -ResourceMeteringSaveInterval $info.ResourceMeteringSaveInterval -NumaSpanningEnabled $info.NumaSpanningEnabled -EnableEnhancedSessionMode $info.EnableEnhancedSessionMode

It may look long and ugly, but the good news is you don’t have to type it out again… all you have to do is copy and paste it from this article!

Of course, you can clean it up a little… if you are not using virtual fibre channel, for example, you could remove all of the parameters that pertain to that.  A lot of companies don’t care about the MAC addresses of their VMs and resource metering, so remove those.  All of a sudden that line gets a lot smaller:

Set-VMHost -VirtualHardDiskPath $info.VirtualHardDiskPath –VirtualMachinePath $info.VirtualMachinePath –MaximumStorageMigrations $info.MaximumStorageMigrations -UseAnyNetworkForMigration $info.UseAnyNetworkForMigration -NumaSpanningEnabled $info.NumaSpanningEnabled -EnableEnhancedSessionMode $info.EnableEnhancedSessionMode

Because PowerShell is plain English, you can easily go through these scripts and customize it the way you like.  No worries, have fun!

Of course, you may have noticed by now that we have not even touched on virtual networks here, and that is certainly an important component.  What do we need for that?  You need to read my next article!

Another tough exam…

As a subject matter expert (SME) on virtualization, I was neither excited nor intimidated when Microsoft announced their new exam, 74-409: Server Virtualization with Windows Server Hyper-V and System Center.  Unlike many previous exams I did not rush out to be the first to take it, nor was I going to wait forever.  I actually thought about sitting the exam in Japan in December, but since I had trouble registering there and then got busy, I simply decided to use my visit to Canada to schedule the exam.

This is not the first exam that I have gone into without so much as a glance at the Overview or the Skills Measured section of the exam page on the Internet.  I did not do any preparation whatsoever for the exam… as you may know I have spent much of the last five years living and breathing virtualization.  This attitude very nearly came back to bite me in the exam room at the Learning Academy in Hamilton, Ontario Wednesday morning.

Having taught every Microsoft server virtualization course ever produced (and having written or tech-reviewed many of them) I should have known better.  Virtualization is more than installing Hyper-V.  it’s more than just System Center Virtual Machine Manager (VMM) and Operations Manager (OpsMgr).  It is the entire Private Cloud strategy… and if you plan to sit this exam you had better have more than a passing understanding of System Center Service Manager (ServMgr), Data Protection Manager (DPM), and Orchestrator.  Oh, and your knowledge should extend beyond more than one simple Hyper-V host.

I have long professed to my students that while DPM is Microsoft’s disaster recovery solution, when it comes down to it just make sure that your backup solution does everything that they need, and make sure to test it.  While I stand behind that statement for production environments, it does not hold water when it comes to Microsoft certification exams.  When two of the first few questions were on DPM I did a little silent gulp to myself… maybe I should have prepared a little better for this.

I do not use Service Manager… It’s not that I wouldn’t – I have a lot of good things to say about it.  Heck, I even installed it as recent as yesterday – but I have not used it beyond a passing glance.  The same used to be true of System Center Orchestrator, but over the last year that has changed a lot… I have integrated it into my courseware, and I have spent some time learning it and using it in production environments for repetitive tasks.  While I am certainly not an expert in it, I am at least more than just familiar with it.  That familiarity may have helped me on one exam question.  Had I taken the time to review the exam page on the Microsoft Learning Experience website I would have known that the word Orchestrator does not appear anywhere on the page.

Here’s the problem with Microsoft exams… especially the newer ones that do not simply cover a product, but an entire solution across multiple suites.  Very few of us will use and know every aspect covered on the exam.  That is why I have always professed that no matter how familiar you may be with the primary technology covered, you should always review the exam page and fill in your knowledge gaps with the proper studying.  You should even spend a few hours reviewing the material that you are pretty sure you do know.  As I told my teenaged son when discussing his exams, rarely will you have easy exams… if you feel it was easy it just means you were sufficiently prepared.  Five questions into today’s exam I regretted my blasé attitude towards it – I may be a virtualization expert, but I was not adequately prepared.

As I went through the exam I started to get into a groove… while there are some aspects of Hyper-V that I have not implemented, those are few and far between.  the questions about VHDX files, Failover Clustering, Shared VHDX, Generation 2 VMs, and so many more came around and seemed almost too easy, but like I told my son it just means I am familiar with the material.  There were one or two questions which I considered to be very poorly worded, but I reread the questions and the answers and gave my best answer based on my understanding of them.

I have often described the time between pressing ‘End Exam’ and the appearance of the Results screen to be an extended period of excruciating forced lessons in patience.  That was not the case today – I was surprised that the screen came up pretty quickly.  While I certainly did not ace the exam, I did pass, and not with the bare minimum score.   It was certainly a phew moment for a guy who considers himself pretty smart in virtualization.

Now here’s the question… is the exam a really tough one, or was I simply not prepared and thus considered it tough?  And frankly, how tough could it have been if I didn’t prepare, and passed anyways?  I suppose that makes two questions.  The answer to both is that while I did not prepare for the exam, I am considered by many (including Microsoft) a SME on Hyper-V and System Center.  I can say with authority that it was a difficult exam.  That then leads to the next question, is it too tough?  While I did give that some thought as I left the exam (my first words to the proctor was ‘Wow that was a tough exam!) I do not think it is unreasonably so.  It will require a lot of preparation – not simply watching the MVA Jump Start videos (which are by the way excellent resources, and should be considered required watching for anyone planning to sit the exam).  You will need to build your own environment, do a lot of reading and research, and possibly more.

If you do plan to sit this exam, make sure you visit the exam page first by clicking here.  Make sure you expand and review the Overview and Skills Measured sections.  If you review the Preparation Materials section it will refer you to a five day course that is releasing next week from Microsoft Learning Experience – 20409A- Server Virtualization with Windows Server Hyper-V and System Center (5 Days).  I am proud to say that I was involved with the creation of that course, and that it will help you immensely, not only with the exam but with your real-world experience.

Incidentally, passing the exam gives you the following cert: Microsoft Certified Specialist: Server Virtualization with Hyper-V and System Center.

Good luck, and go get em!

Building the IT Camp with PowerShell Revisited

I always said I am not hard to please… I only need perfection.  So when I wrote my PowerShell script to build my environment the other day I was pleased with myself… until I realized a huge flaw in it.  Generation 1.

Actually to be fair, there is nothing wrong with Generation 1 virtual machines in Hyper-V; they have served us all well for several years.  However how could I claim to live on the bleeding edge (Yes, I have made that claim many times) and yet stay safe with Generation 1?

In the coming weeks Windows Server 2012 R2 will become generally available.  One of the huge changes that we will see in it is Generation 2 virtual machine hardware.  Some of the changes in hardware levels include UEFI, Secure Boot, Boot from SCSI, and the elimination of legacy hardware (including IDE controllers and Legacy NICs).

Of course, since Generation 1 hardware is still fully supported, we need to identify when we create the VM which Generation it will be, and this cannot later be changed.

I had forgotten about this, and when I created the script (of which I was quite proud) I did not think of this.  It was only a few hours later, as I was simultaneously installing nine operating systems, that I noticed in the details pane of my Hyper-V Manager that all of my VMs were actually Gen1.

Crap.

Remember when I said a couple of paragraphs ago that the generation level cannot be changed?  I wasn’t kidding.  So rather than living with my mistake I went back to the drawing board.  I found the proper cmdlet switches, and modified my script accordingly.

As there is a lot of repetition in it, I am deleing six of the nine VMs from the list.  You are not missing out on anything, I assure you.

# Script to recreate the infrastructure for the course From Virtualization to the Private Cloud (R2).
# This script should be run on Windows Server 2012 R2.
# This script is intended to be run within the Boot2VHDX environment created by Mitch Garvis
# All VMs will be created as Generation 2 VMs (except the vCenter VM for which it is not supported).
# All VMs will be configured for Windows Server 2012 R2
# System Center 2012 R2 will be installed.

# Variables

$ADM = "Admin"                # VM running Windows 8.1 (for Administration)
$ADMMIN = 512MB                # Minimum RAM for Admin
$ADMMAX = 2GB                # Maximum RAM for Admin
$ADMVHD = 80GB                # Size of Hard Drive for Admin

$SQL = "SQL"                # VM (SQL Server)
$SQLMIN = 2048MB            # Minimum RAM assigned to SQL
$SQLMAX = 8192MB            # Maximum RAM assigned to SQL
$SQLCPU = 2                # Number of CPUs assigned to SQL
$SQLVHD = 200GB                # Size of Hard Drive for SQL

$VCS = "vCenter"             # VM (vSphere vCenter Cerver) (Windows Server 2008 R2)
$VCSMIN = 2048MB             # Minimum RAM assigned to vCenter
$VCSMAX = 4096MB             # Maximum RAM assigned to vCenter
$VCSCPU = 2                 # Number of CPUs assigned to vCenter
$VCSVHD = 200GB                # Size of Hard Drive for vCenter

$VMLOC = "C:\HyperV"            # Location of the VM and VHDX files

$NetworkSwitch1 = "CorpNet"        # Name of the Internal Network

$W81 = "E:\ISOs\Windows 8.1 E64.iso"            # Windows 8.1 Enterprise
$WSR2 = "E:\ISOs\Windows Server 2012 R2.iso"        # Windows Server 2012 R2
$W2K8 = "E:\ISOs\Windows Server 2008 R2 SP1.iso"     # Windows Server 2008 R2 SP1

# Create VM Folder and Network Switch
MD $VMLOC -ErrorAction SilentlyContinue
$TestSwitch1 = Get-VMSwitch -Name $NetworkSwitch1 -ErrorAction SilentlyContinue; if ($TestSwitch1.Count -EQ 0){New-VMSwitch -Name $NetworkSwitch1 -SwitchType Internal}

# Create & Configure Virtual Machines
New-VM -Name $ADM -Generation 2 -Path $VMLOC -MemoryStartupBytes $ADMMIN -NewVHDPath $VMLOC\$ADM.vhdx -NewVHDSizeBytes $ADMVHD -SwitchName $NetworkSwitch1
Set-VM -Name $ADM -DynamicMemory -MemoryMinimumBytes $ADMMIN -MemoryMaximumBytes $ADMMAX
Add-VMDvdDrive $ADM | Set-VMDvdDrive -VMName $ADM -Path $W81

New-VM -Name $SQL -Generation 2 -Path $VMLOC -MemoryStartupBytes $SQLMIN -NewVHDPath $VMLOC\$SQL.vhdx -NewVHDSizeBytes $SQLVHD -SwitchName $NetworkSwitch1
Set-VM -Name $SQL -DynamicMemory -MemoryMinimumBytes $SQLMIN -MemoryMaximumBytes $SQLMAX -ProcessorCount $SQLCPU
Add-VMDvdDrive $SQL | Set-VMDvdDrive -VMName $SQL -Path $WSR2

New-VM -Name $VCS -Path $VMLOC -MemoryStartupBytes $VCSMIN -NewVHDPath $VMLOC\$VCS.vhdx -NewVHDSizeBytes $VCSVHD -SwitchName $NetworkSwitch1
Set-VM -Name $VCS -DynamicMemory -MemoryMinimumBytes $VCSMIN -MemoryMaximumBytes $VCSMAX -ProcessorCount $VCSCPU
Set-VMDvdDrive -VMName $VCS -Path $W2K8

#Start Virtual Machines
Start-VM $ADM
Start-VM $SQL
Start-VM $VCS

In the script you can see a few differences between my original script (in the article) and this one.  Firstly on all machines that are running Windows 8.1 or Windows Server 2012 R2 I have set the switch –Generation 2.  That is simple enough.

Adding the virtual DVD was a little trickier; with Generation 1 hardware there was a ready IDE port for you to connect the .ISO file to.  In Gen 2 it is all about SCSI, so you have to use the Add-VMDvdDrive cmdlet, and then connect the .ISO file (Set-VMDvdDrive –VMName <Name> –Path <ISO Path>Not only for simplicity but also to demonstrate that you can I have put these two cmdlets on a single line, connected with a pipe (the | key).

I want to thank a couple of colleagues for helping me out with the Generation 2 hardware and DVD issues… especially Sergey Meshcheryakov , who was quick to answer.  The exact cmdlet switches were not easy to track down!

…and remember, if I can learn it, so can you!  Even the great Sean Kearney once did not know anything about PowerShell… and now look at him!

Building an IT Camp with PowerShell

I have been telling people for a couple of years that if they want to ensure a good future in the IT field there are two things to learn: System Center and PowerShell.  I unfortunately am quite good with one, but have been referring to myself as a scripting luddite for quite some time.  It is just something that I have not had the chance to learn.  After all, as a trainer and (Virtual) Evangelist I have not really had a lot of opportunity to get my hands on the type of environment where it would come in handy.

Recently I was in a conversation with a colleague who was complaining that he was too busy all of the time, and was really not enjoying his job because he hardly had time to breathe.  I asked him what sort of tasks he did on a regular basis, and when he told me my answer was simple: ‘If you have to do a task only once, do it manually.  If you might have to do it twice or more… automate it.’  In other words, learn PowerShell.

As I walked away from that meeting I realized that I was a hypocrite.  I built the labs for my course, From Virtualization to the Private Cloud, by hand, and every time I had to rebuild the environment I was doing it manually.  Considering the scope of what was involved I was not only being a hypocrite, I was being stupid.

Time is money, and time wasted is money lost.  I was scheduled to teach a four hour seminar on Hyper-V at the end of last week, and I decided that I was going to include some PowerShell management into that session.  I sat down and learned the basics, and that resulted not only in a better for the attendees last Friday, but also in an article titled Managing Hyper-V Virtual Machines with Windows PowerShell.  I started with some basics, how to start and stop VMs, how to check the VM memory, things like that.  I then expanded into creating a virtual machine, and adjusting the settings for it.  I was thrilled to be able to do all of this from the command line.

Okay, that was great, but now I needed to create a script that would really help me.  I knew there wouldn’t be anything on-line that would be exactly what I needed, but I was sure I would find the basics out there.  I found a great article by Neil Tucker on how he builds a couple of virtual machines for his course 50331 (Windows 7, Enterprise Desktop Support Technician).  Neil’s article gave me the basic framework for what I would come up with, including how to set variables for different VMs such as name, memory, and hard drive size.  It even went so far as to attach the proper ISO file to each VM and installs the OS using answer files.  As I already have my hard drives built I didn’t need that… but I was going to take things a little farther than Neil did.

I needed to build a script that would build nine virtual machines, each of which has its own special requirements.  I also needed to ensure that they would be connected to a virtual switch (which I would have to build as well if it wasn’t already there).

Although strictly speaking I do not need my script to create the VHDX files for me, I do want to make sure that each VM will connect to my pre-created virtual hard drive files, so I wrote the script to go through the motion of creating them in the correct place; I can then simply copy over them.

Up to now I have delivered the course on standard laptops (HP EliteBook 8570w with 32GB RAM).  However this likely would not be the case going forward, so it was important that I write the script so that I could easily provision new hardware with the course.

Goals:

  1. Create a virtual switch for the course (check to see that it does not already exist)
  2. Create a repository for all course virtual machines and virtual hard disk files to reside
  3. Create nine virtual machines, each with their own settings for dynamic memory, CPUs.
  4. Connect all virtual machines to the virtual network switch
  5. (For extra credit) attach the appropriate OS DVD to each virtual machine
  6. Start all of the virtual machines.

While I thought about allowing the person running the script to choose their VM names, I decided that this would make it confusing for attendees running the courseware labs, where I have set the VM names appropriately.

Here is what I came up with:

# Script to recreate the infrastructure for the course From Virtualization to the Private Cloud (R2).
# This script should be run on Windows Server 2012 R2.
# This script is intended to be run within the Boot2VHDX environment created by Mitch Garvis
# All VMs will be configured for Windows Server 2012 R2 unless otherwise stated

# Variables

$ADM = “Admin”                # VM running Windows 8.1 (for Administration)
$ADMMIN = 512MB                # Minimum RAM for Admin
$ADMMAX = 2GB                # Maximum RAM for Admin
$ADMVHD = 80GB                # Size of Hard Drive for Admin

$DC1 = “DC1″                # VM (Domain Controller) (Windows Server Core)
$DC1MIN = 512MB                # Maximum RAM assigned to DC1
$DC1MAX = 2048MB            # Maximum RAM assigned to DC1
$DC1VHD = 30GB                # Size of Hard Drive for DC1

$SQL = “SQL”                # VM (SQL Server)
$SQLMIN = 2048MB            # Minimum RAM assigned to SQL
$SQLMAX = 8192MB            # Maximum RAM assigned to SQL
$SQLCPU = 2                # Number of CPUs assigned to SQL
$SQLVHD = 200GB                # Size of Hard Drive for SQL

$STOR = “Storage”            # VM (Storage Spaces, iSCSI Target)
$STORMIN = 512MB             # Minimum RAM assigned to Storage
$STORMAX = 2048MB             # Maximum RAM assigned to Storage
$STORVHD = 30GB                # Size of first Hard Drive for Storage
$STORVHD2 = 100GB            # Size of second Hard Drive for Storage
$STORVHD3 = 100GB            # Size of third Hard Drive for Storage

$VMM = “VMM”                # VM (System Center Virtual Machine Manager)
$VMMMIN = 2048MB             # Minimum RAM assigned to VMM
$VMMMAX = 8192MB             # Maximum RAM assigned to VMM
$VMMCPU = 2                 # Number of CPUs assigned to VMM
$VMMVHD = 100GB                # Size of Hard Drive for VMM

$OM = “OpsMgr”                # VM (System Center Operations Manager)
$OMMIN = 2048MB             # Minimum RAM assigned to OpsMgr
$OMMAX = 8192MB             # Maximum RAM assigned to OpsMgr
$OMCPU = 2                 # Number of CPUs assigned to OpsMgr
$OMVHD = 100GB                # Size of Hard Drive for OpsMgr

$ORC = “Orchestrator”             # VM (System Center Orchestrator)
$ORCMIN = 2048MB            # Minimum RAM assigned to Orchestrator
$ORCMAX = 8192MB             # Maximum RAM assigned to Orchestrator
$ORCCPU = 2                 # Number of CPUs assigned to Orchestrator
$ORCVHD = 100GB                # Size of Hard Drive for Orchestrator

$SM = “SrvMgr”                 # VM (System Center Service Manager)
$SMMIN = 2048MB             # Minimum RAM assigned to Service Manager
$SMMAX = 8192MB             # Maximum RAM assigned to Service Manager
$SMCPU = 2                 # Number of CPUs assigned to Service Manager
$SMVHD = 100GB                # Size of Hard Drive for Service Manager

$VCS = “vCenter”             # VM (vSphere vCenter Cerver) (Windows Server 2008 R2)
$VCSMIN = 2048MB             # Minimum RAM assigned to vCenter
$VCSMAX = 4096MB             # Maximum RAM assigned to vCenter
$VCSCPU = 2                 # Number of CPUs assigned to vCenter
$VCSVHD = 200GB                # Size of Hard Drive for vCenter

$VMLOC = “C:\HyperV”            # Location of the VM and VHDX files

$NetworkSwitch1 = “CorpNet”        # Name of the Internal Network

$W81 = “E:\ISOs\Windows 8.1 E64.iso”            # Windows 8.1 Enterprise
$WSR2 = “E:\ISOs\Windows Server 2012 R2.iso”        # Windows Server 2012 R2
$W2K8 = “E:\ISOs\Windows Server 2008 R2 SP1.iso”    # Windows Server 2008 R2 SP1

# Create VM Folder and Network Switch
MD $VMLOC -ErrorAction SilentlyContinue
$TestSwitch1 = Get-VMSwitch -Name $NetworkSwitch1 -ErrorAction SilentlyContinue; if ($TestSwitch1.Count -EQ 0){New-VMSwitch -Name $NetworkSwitch1 -SwitchType Internal}

# Create Virtual Machines
New-VM -Name $ADM -Path $VMLOC -MemoryStartupBytes $ADMMIN -NewVHDPath $VMLOC\$ADM.vhdx -NewVHDSizeBytes $ADMVHD -SwitchName $NetworkSwitch1
Set-VM -Name $ADM -DynamicMemory -MemoryMinimumBytes $ADMMIN -MemoryMaximumBytes $ADMMAX

New-VM -Name $DC1 -Path $VMLOC -MemoryStartupBytes $DC1MIN -NewVHDPath $VMLOC\$DC1.vhdx -NewVHDSizeBytes $DC1VHD -SwitchName $NetworkSwitch1
Set-VM -Name $DC1 -DynamicMemory -MemoryMinimumBytes $DC1MIN -MemoryMaximumBytes $DC1MAX

New-VM -Name $SQL -Path $VMLOC -MemoryStartupBytes $SQLMIN -NewVHDPath $VMLOC\$SQL.vhdx -NewVHDSizeBytes $SQLVHD -SwitchName $NetworkSwitch1
Set-VM -Name $SQL -DynamicMemory -MemoryMinimumBytes $SQLMIN -MemoryMaximumBytes $SQLMAX -ProcessorCount $SQLCPU

New-VM -Name $STOR -Path $VMLOC -MemoryStartupBytes $STORMIN -NewVHDPath $VMLOC\$STOR.vhdx -NewVHDSizeBytes $STORVHD -SwitchName $NetworkSwitch1
Set-VM -Name $STOR -DynamicMemory -MemoryMinimumBytes $STORMIN -MemoryMaximumBytes $STORMAX

New-VM -Name $VMM -Path $VMLOC -MemoryStartupBytes $VMMMIN -NewVHDPath $VMLOC\$VMM.vhdx -NewVHDSizeBytes $VMMVHD -SwitchName $NetworkSwitch1
Set-VM -Name $VMM -DynamicMemory -MemoryMinimumBytes $VMMMIN -MemoryMaximumBytes $VMMMAX -ProcessorCount $VMMCPU

New-VM -Name $ORC -Path $VMLOC -MemoryStartupBytes $ORCMIN -NewVHDPath $VMLOC\$ORC.vhdx -NewVHDSizeBytes $ORCVHD -SwitchName $NetworkSwitch1
Set-VM -Name $ORC -DynamicMemory -MemoryMinimumBytes $ORCMIN -MemoryMaximumBytes $ORCMAX -ProcessorCount $ORCCPU

New-VM -Name $OM -Path $VMLOC -MemoryStartupBytes $OMMIN -NewVHDPath $VMLOC\$OM.vhdx -NewVHDSizeBytes $OMVHD -SwitchName $NetworkSwitch1
Set-VM -Name $OM -DynamicMemory -MemoryMinimumBytes $OMMIN -MemoryMaximumBytes $OMMAX -ProcessorCount $OMCPU

New-VM -Name $SM -Path $VMLOC -MemoryStartupBytes $SMMIN -NewVHDPath $VMLOC\$SM.vhdx -NewVHDSizeBytes $SMVHD -SwitchName $NetworkSwitch1
Set-VM -Name $SM -DynamicMemory -MemoryMinimumBytes $SMMIN -MemoryMaximumBytes $SMMAX -ProcessorCount $SMCPU

New-VM -Name $VCS -Path $VMLOC -MemoryStartupBytes $VCSMIN -NewVHDPath $VMLOC\$VCS.vhdx -NewVHDSizeBytes $VCSVHD -SwitchName $NetworkSwitch1
Set-VM -Name $VCS -DynamicMemory -MemoryMinimumBytes $VCSMIN -MemoryMaximumBytes $VCSMAX -ProcessorCount $VCSCPU

# Configure Virtual Machines
Set-VMDvdDrive -VMName $ADM -Path $W81
Set-VMDvdDrive -VMName $DC1 -Path $WSR2
Set-VMDvdDrive -VMName $SQL -Path $WSR2
Set-VMDvdDrive -VMName $STOR -Path $WSR2
Set-VMDvdDrive -VMName $VMM -Path $WSR2
Set-VMDvdDrive -VMName $OM -Path $WSR2
Set-VMDvdDrive -VMName $ORC -Path $WSR2
Set-VMDvdDrive -VMName $SM -Path $WSR2
Set-VMDvdDrive -VMName $VCS -Path $W2K8

Start-VM $ADM
Start-VM $DC1
Start-VM $SQL
Start-VM $STOR
Start-VM $VMM
Start-VM $OM
Start-VM $ORC
Start-VM $SM
Start-VM $VCS

Please remember that until a little under a week ago I had not written a single script longer than a couple of lines.  While I am sure there are efficiencies that can be improved upon, I don’t think it’s too bad for a first go at it.

So now that I am scripting, what do you think you could come up with?  The way I see it, if I could do it… anyone can!

Managing Hyper-V Virtual Machines with Windows PowerShell

Warning: The following post was written by a scripting luddite.  The author readily admits that he would have difficulty coding his way out of a paper bag, and if the fate of the world depended on his ability to either write code or develop software then you had better start hoarding bottled water and cans of tuna.  Fortunately for everyone, there are heroes to help him!

I love the Graphical User Interface (GUI).  I use it every day in both the Windows client and Windows Server operating systems.  It makes my life easier on a day to day basis.

With that being said, there are several tasks that administrators must do on a regular basis.  There is no simple and reliable way to create repetitive task macros in the GUI.  Hence we can either work harder, or we can learn to use scripting tools like Windows PowerShell.

Along the way I have gotten some help from some friends.  Ed Wilson’s books have provided a wealth of information for me, and Sean Kearney has been my go-to guy when I need help.  There was a time when I was teaching a class and was asked ‘Can PowerShell do that?’  I replied by saying that if I asked Sean Kearney to write a PowerShell script to tie my shoes, I was reasonably sure he could do it because PowerShell can do ANYTHING.  Well one of my students posted that comment on Twitter, and got the following reply from Sean (@EnergizedTech):

Get-Shoe | Invoke-Tie

It makes sense too…because PowerShell works with a very simple Verb-Noun structure, and if you speak English it is easy to learn.

I may be a scripting luddite, but I do know a thing or two about virtualization, and especially Hyper-V.  So it only stands to reason that if I was going to start learning (and even scarier, teaching) PowerShell, I would start with the Hyper-V module.  As a good little Microsoft MVP and Community Leader, it only makes sense that I would take you along for the ride :)

Most of what can be done in PowerShell can also be done in the GUI.  If I want to see a list of the virtual machines on my system, I simply open the Hyper-V Manager and there it is.

Get-GUI

PowerShell is almost as simple… Type Get-VM.

Get-PS

By the way you can filter it… if you only want virtual machines that start with the letter S, try:

Get-VM S*

One of the advantages of PowerShell is that it allows you to manage remote servers, rather than having to log into them you can simply run scripts against them.  If you have a server called SWMI-Host1, you can simply type:

Get-VM –Server SWMI-Host1

Starting and stopping virtual machines is simple…

Start-VM Admin

Stop-VM VMM

Again, your wildcards will work here:

Start-VM O*

This command will start all VMs that start with the letter O.

If you want to check how much memory you have assigned to all of your virtual machines (very useful when planning as well as reporting) simply run the command:

Get-VMMemory *

Get-VMMemory

I did mention that you could use this command for reporting… to make it into an HTML report run the following:

Get-VMMemory * | ConvertTo-HTML | Out-File c:\VMs\MemReport.htm

To make it into a comma separated values (CSV) file that can easily be read in Microsoft Office Excel, just change the command slightly:

Get-VMMemory * | ConvertTo-CSV | Out-File c:\VMs\MemReport.csv

The report created is much more detailed than the original screen output, but not so much so as to be unusable.  See:

Making Changes

So far we have looked at VMs, we have started and stopped them… but we haven’t actually made any changes to them. Let’s create a new virtual machine, then make the changes we would make in a real world scenario.

New-VM –Name PSblog –MemoryStartupBytes 1024MB –NewVHDPath c:\VHDs\PSblog.vhdx –NewVHDSizeBytes 40GB –SwitchName CorpNet

With this simple script I created a virtual machine named PSblog with 1024MB of RAM, a new virtual hard disk called PSblog.vhdx that is 40GB in size, and connected it to CorpNet.

Now that will work, but you are stuck with static memory.  Seeing as one of the great features of Hyper-V is Dynamic Memory, let’s use it with the following script:

Set-VMMemory –VMName PSblog –DynamicMemoryEnabled $true –MinimumBytes 512MB –StartupBytes 1024MB MaximumBytes 2048MB

Now we’ve enabled dynamic memory for this VM, setting the minimum to 512MB, the maximum to 2048MB, and of course the startup RAM to 1024MB.

For the virtual machine we are creating we might need multiple CPUs, and because some of our hosts may be newer and other ones older we should set the compatibility mode on the virtual CPU to make sure we can Live Migrate between all of our Intel-based hosts:

Set-VMProcessor –VMName PSblog –Count 4 –CompatibilityForMigrationEnabled $true

At this point we have created a new virtual machine, configured processor, memory, networking, and storage (the four food groups of virtualization), and are ready to go.

I will be delving deeper into Hyper-V management with PowerShell over the next few weeks, so stay tuned!

NOTE: While nothing in this article is plagiarized, I do want to thank a number of sources, on whose expertise I have leaned rather heavily.  Brien Posey has a great series of articles on Managing Hyper-V From the Command Line on www.VirtualizationAdmin.com which is definitely worth reading.  He focuses on an add-on set of tools called the Hyper-V Management Library (available from www.Codeplex.com) so many of the scripts he discusses are not available out of the box, but the articles are definitely worth a read.  Rob McShinsky has an article on SearchServerVirtualization (a www.TechTarget.com property) called Making sense of new Hyper-V 2012 PowerShell cmdlets which is great, and links to several scripts for both Server 2008 R2 and Server 2012.  Thanks to both of them for lending me a crutch… you are both worthy of your MVP Awards!

Counting Down the Classics with the US IT Evangelists

 

On the first day of Christmas my true love gave to me…”

Ninety-nine bottles of beer on the wall…”

“Thirty-five articles on Virtualization…”

Pale AleAll of these are great sing-along songs, whether for holidays, camping, bus-rides, or comparing virtualization technology.  Each one is a classic.

Wait… you’ve never heard the last one? That’s okay, we are happy to teach it to you.  It has a pretty catchy tune – the tune of cost savings, lower TCO, higher ROI, and a complete end-to-end management solution.

Even if you can’t remember the lyrics, why don’t you open up the articles – each one written by a member of Microsoft’s team of IT Pro Evangelists in the United States.

You can read along at your own pace, because no matter how fast or slow you read, as long as you are heading in the right direction then you are doing it right! –MDG

The 35 Articles on Virtualization:

Date Article Author
12-Aug-13 Series Introduction Kevin Remde – @KevinRemde
13-Aug-13 What is a “Purpose-Built Hypervisor? Kevin Remde – @KevinRemde
14-Aug-13 Simplified Microsoft Hyper-V Server 2012 Host Patching = Greater Security and More Uptime Chris Avis – @ChrisAvis
15-Aug-13 Reducing VMware Storage Costs WITH Windows Server 2012 Storage Spaces Keith Mayer – @KeithMayer
16-Aug-13 Does size really matter? Brian Lewis – @BrianLewis_
19-Aug-13 Let’s talk certifications! Matt Hester – @MatthewHester
20-Aug-13 Virtual Processor Scheduling Tommy Patterson – @Tommy_Patterson
21-Aug-13 FREE Zero Downtime Patch Management Keith Mayer – @KeithMayer
22-Aug-13 Agentless Protection Chris Avis – @ChrisAvis
23-Aug-13 Site to Site Disaster Recovery with HRM Keith Mayer – @KeithMayer
25-Aug-13 Destination: VMWorld Jennelle Crothers – @jkc137
26-Aug-13 Get the “Scoop” on Hyper-V during VMworld Matt Hester – @MatthewHester
27-Aug-13 VMWorld: Key Keynote Notes Kevin Remde – @KevinRemde
28-Aug-13 VMWorld: Did you know that there is no extra charge? Kevin Remde – @KevinRemde
29-Aug-13 VMWorld: A Memo to IT Leadership Yung Chou – @YungChou
30-Aug-13 Moving Live Virtual Machines, Same But Different Matt Hester – @MatthewHester
02-Sep-13 Not All Memory Management is Equal Dan Stolts – @ITProGuru
03-Sep-13 Can I get an app with that? Matt Hester – @MatthewHester
04-Sep-13 Deploying Naked Servers Matt Hester – @MatthewHester
05-Sep-13 Automated Server Workload Balancing Keith Mayer – @KeithMayer
06-Sep-13 Thoughts on VMWorld Jennelle Crothers – @jkc137
09-Sep-13 Shopping for Private Clouds Keith Mayer – @KeithMayer
11-Sep-13 Dynamic Storage Management in Private Clouds Keith Mayer – @KeithMayer
12-Sep-13 Replaceable? or Extensible? What kind of virtual switch do you want? Chris Avis – @ChrisAvis
13-Sep-13 Offloading your Storage Matt Hester – @MatthewHester
16-Sep-13 VDI: A Look at Supportability and More! Tommy Patterson – @Tommy_Patterson
17-Sep-13 Agentless Backup for Virtual Environments Special Guest Chris Henley – @ChrisJHenley
19-Sep-13 How robust is your availability? Kevin Remde – @KevinRemde
20-Sep-13 VM Guest Operating System Support Brian Lewis – @BrianLewis_
23-Sep-13 How to license Windows Server VMs Brian Lewis – @BrianLewis_
24-Sep-13 Comparing vSphere 5.5 and Windows Server 2012 R2 Hyper-V At-A-Glance Keith Mayer – @KeithMayer
25-Sep-13 Evaluating Hyper-V Network Virtualization as an alternative to VMware NSX Keith Mayer – @KeithMayer
26-Sep-13 Automation is the Key to Happiness Matt Hester – @MatthewHester
27-Sep-13 Comparing Microsoft’s Public Cloud to VMware’s Public Cloud Blain Barton – @BlainBar
30-Sep-13 What does AVAILABILITY mean in YOUR cloud? Keith Mayer – @KeithMayer

…and as for me? Well it’s pretty simple… just go to www.garvis.ca and type Virtualization into the search bar.  You’ll see what I have to say too!

Hyper-V CPU Compatibility Mode

it is pretty well known that for Live Migration to work in Hyper-V, the CPUs on the hosts must be of the same family (Intel to Intel, AMD to AMD).  However it is not as simple as that. 

Both companies are constantly improving their products, so a CPU that Intel makes in 2013 will have more features than one they made in 2010, and because of that they will not be compatible for Live Migration.  In theory then, the Live Migration window is really closer to eighteen months before you are out of band.

So how impractical would it be if both VMware and Microsoft told companies that in order to have Live Migration their servers had to be less than eighteen months apart?  So several years ago Intel and VMware got together and addressed the problem.  The result was what they called Enhanced vMotion Compatibility (EVC).  Essentially what they do for servers in a cluster where EVC is enabled is they simply mask the advanced features of the newer CPUs, which are usually only needed for sound and video and thus not for the majority of business servers.

Microsoft then introduced Hyper-V, and overnight (five years later) they are a real player in the virtualization realm.  In fact, there are some people who would say that they are equal to or better than VMware.  They need to implement a similar feature to prevent the same issue.  Unfortunately they can’t call it EVC because that includes VMware’s trademark vMotion.  Being better with technology than they are with marketing, they settled on calling it ‘Migrate to a physical computer with a different processor version…’ or MTAPCWADPV.  Try to say that three times fast ;)

While their feature name is nowhere near as easy as the equivalent from their competition, the technology is applied to the virtual machine rather than to the cluster.  So in your environment you could have a cluster where some VMs could migrate to some hosts but not to others.

image

Now here’s the misconception: People seem to think that by enabling MTAPCWADPV you are sacrificing performance on your VMs.  Nothing could be further from the truth. 

The performance reduction of CPU compatibility mode is a myth.  What MTAPCWADPV does is it masks the newer features of the CPU – mostly multi-media signatures and such – but does not otherwise hobble the CPU.  Unless your VM requires those newer features there will be absolutely no performance decrease to the VM.  If they have VMs that DO need the newer CPU features then leave those on the newer blades.

The other myth, of course, is that it allows you to Live Migrate from Intel to AMD or vice versa.  Unfortunately that is not possible.  Will it be in the future?  Who knows… but under the hood the two families are still different enough that I don’t expect to see it anytime soon.

  1. So now that you know, go enable MTAPCWADPV!  Here’s how:
  2. Open the Settings window of your VM
  3. Expand the Processor section.
  4. Click on Compatibility.
  5. Select the check box called Migrate to a physical computer with a different processor version.

That’s it!  The only caveat is that the VM must be turned off before you do it.  Messing with the processor is not something you want to do live ;)

Live Migration can be performed between any servers with compatible CPUs… as long as they are within the same family.  Try it yourself!