Category Archives: Hyper-V

Hyper-V 2008 R2: Still good enough?

I manage a vSphere environment at work, and it is a real change from the last few years when I spent all of my time talking about Hyper-V.  I want to be clear – it is not better or worse, it is just… different.  We have a number of virtualization hosts, plus a physical domain controller, and one physical server running Windows Server 2008 R2 (Enterprise), which has an app running that precludes us from changing that.  The app hardly uses any memory, so a lot of that was wasted.

While my physical server does not have a lot of RAM (8GB) it has a ridiculous amount of internal storage… I mean terabytes and terabytes of it.  I asked my boss about it, and he said it was there for something that they no longer use the server for… but it’s there… wasted as well… for now.

A few weeks ago I proposed a project that would require use of that space, and it was tentatively approved.  The problem is that the existing application and the proposed application are not supposed to co-exist on the same server.  I would have to come up with a way to segregate them.  No problem… I would install the Hyper-V role onto the physical server, and then create a new virtual machine for my purposes.

Once I explained to my boss that no extra licensing was required – because the physical server is licensed for Windows Server 2008 R2 Enterprise Edition, we could build as many as four virtual machines on the same license on that host – he got excited, and asked the usual ‘what else can we do?’ questions.

‘Can we cluster the virtual machine?’

No.  I mean, we could, but it would require having a second Hyper-V host which we do not have.  There is nothing we can do about that without incurring extra costs… and the purpose of the exercise is to do it for zero dollars.

‘Can we use Storage Spaces?’

No.  Storage Spaces is a great technology – one that I really loved talking about when I was working with Microsoft.  However it is a feature that was only introduced in Windows Server 2012, and we are only on Server 2008 R2.

‘Can we create the VM using 64TB .vhdx drives?’

No.  Again, .VHDX files were only introduced in Windows Server 2012.  We are limited to 2TB .VHD files… which is more than enough for our actual needs anyways.

‘How about UEFI Boot on the VM’

Nope.  Generation 2 hardware was introduced in Windows Server 2012 R2, so we are stuck with Generation 1 hardware.

So after he struck out on all of these questions, he asked me the question I was expecting… ‘Then why bother?’

I became a fan of Hyper-V as soon as it was released in Windows Server 2008.  Yes, the original.  I was not under any delusions that it was as good as or better than ESX, but it was free and it didn’t require anything to install… and if you knew Windows then you didn’t need to learn much more to manage it.

Of course it got much better in Windows Server 2008 R2, and even better in the SP1 release… and then in Windows Server 2012 it broke through, and was (in my opinion) as good as or better than vSphere… in some ways it was almost as good, in some ways it was better, and in the balance it came out even. Of course Server 2012 R2 made even better improvements, but when I spent three years with Microsoft Canada – first as a Virtual Partner Technology Advisor and then as a Virtual Evangelist – criss-crossing the country (and the US and the globe) evangelizing Hyper-V in Windows Server 2012 I was confident when I said that at last Microsoft Virtualization was on a par with VMware.

I would never have said that about Hyper-V in Windows Server 2008 R2. Sorry Microsoft, it was good… but vSphere was better.

However in this case we are not comparing Microsoft versus VMware… we are not deciding which platform to implement, because VMware is not an option. We are not even comparing the features of vOld versus vNew… because vNew is still not an option.

All we are deciding is this: Does the version of Hyper-V that is available to us for this project good enough for what our needs are for the project? Let’s review:

  • We need to create a virtual machine with 4GB of RAM. YES.
  • We need that VM to support up to 4TB of storage. YES. (We cannot do it on a single volume, but that is not a requirement)
  • We need the VM to be able to join a domain with FFL and DFL of Windows Server 2008 R2. YES.
  • We need the virtual machine to be backed up on a nightly basis using the tools available to us. YES

That’s it… we have no other requirements. All of our project needs are met by Hyper-V on Windows Server 2008 R2. Yes, Microsoft would love for us to pay to upgrade the host operating system, but they got their money for this server when we bought the license in 2011, and unless they are willing to give us a free upgrade (there is no Software Assurance on the existing license) and pay to upgrade the existing application to work on Server 2012R2 then there is nothing that we can do for them… and frankly if we were in the position where we were going to have to redeploy the whole server, it would be on VMware anyways, because that is what our virtualization environment runs on.

I spent two years evangelizing the benefits of a hybrid virtualization environment, and how well it can be managed with System Center 2012 R2… and that is what we are going to have. I have purchased the System Center licenses and am thrilled that I will be able to manage both my vSphere and my Hyper-V from one console… and for those of you who were paying attention that is what I spent the last three years recommending.

I can hold my head up high because I am running my environment exactly how I recommended all of you run yours… so many of my audience complained (when I was with Microsoft) that my solutions were not real-world because the real world was not exclusively Microsoft. That was never what I was recommending… I was recommending that the world does not need to be entirely VMware either… the two can coexist very well… with a little bit of knowledge and understanding!

Surface Pro 3: Two weeks later

Are there problems with it?  Yes.

Do I absolutely love it? I love my kids and my dogs… but I suppose I do like it as much as I have ever liked a laptop or tablet… and I have had quite a few of them over the years!

What are the problems? There is really only one that you should be aware of if you are thinking of going out to buy one.  It’s the patches and the battery.

How, you may ask, do patches and batteries wind their way into a single problem?  Simple… as you probably know, everything in computers is managed by software drivers… and that includes the battery to some extent.  When you buy the device (or any device) you are prompted to apply patches, and at this point a couple of them for the Surface Pro 3 are firmware updates.  You apply the first one, and then you have a problem…

…Windows tells you there is no battery detected.  Worse, if you unplug the device it shuts off immediately.  The firmware update actually tells the computer that there is no battery installed.

BUT THERE IS! Wait a minute!  I was using it unplugged just a few minutes ago!  Where did it go?  Oh… I get it!  The pesky firmware is what screwed me up.  Let’s check to see if there is ANOTHER firmware update.  Plug it in, connect to the Internet, run Windows Update… By Jove, there it is!  Install it, and presto changeo, there’s my battery!

…and what a battery it is!  My original Surface Pro probably gave me 3 hours of battery (with Hyper-V and a bunch of other things draining it).  The Surface Pro 2 was probably closer to 5.  The Pro 3? I haven’t had it run dry on me yet… for the first time in my laptop-owning life I am not afraid to leave the house in the morning without the charger.

THE SCREEN BOSS, THE SCREEN!
(Imagine the voice of Hervé Villechaize if you would…)

Yes, there are a lot of improvements over the Surface Pro 2, but wow I never would have imaginged that the 1.4″ difference in screen size (12″ over 10.6″) would make that much of a difference.  As I told you recently I have an external 16″ screen that I keep in the trunk of my car so that I can have the dual screen experience on the go.  I don’t know that I have pulled it out once since I got the Pro 3… the combination of the slightly bigger screen and the much improved screen resolution make the extra screen redundant… at least when I am on the go.

Don’t get me wrong… the day the Pro 3 docking station is available I am buying it – I have pre-ordered it from the Microsoft Store, and I have the voucher for it (from something else I returned).  All I need is the e-mail saying it is in… and I expect that to be around the same time the remaining Surface Pro 3 models (with the Intel i3 and i7 CPUs) are released, sometime in August.  When I am at home (or an office) I will still want the multi-screen experience.  On the go?  Not necessary anymore.

A lot of people are saying I should have waited for the Intel i7 version, but the reality is I have not found myself lacking.  The Surface Pro 3 runs everything I need it to with 8GB of RAM and the Intel Core i5 CPU, and frankly I don’t want to spend the extra money (the i7 version will come in two models – 256GB storage for $1,599, and the 512GB model for $1,999.  Too rich for my blood, but thanks!

Conclusion

I am asked pretty often (including 3 minutes ago, as I sit at the Microsoft Store in Square One Mall blogging) whether the Surface Pro 3 is really a laptop replacement.  The answer, as with everything, is that it depends.  I would think that for the vast majority of people the answer is yes.  If you are a true hard-core gamer? Maybe not; there are some gamers who need more than 8gb of RAM.  If you are a coder? I have a friend who is a programmer who needs to run virtual machines running more than 8gb of RAM at all times.  (Did I mention that I LOVE the fact that it runs Hyper-V?  Well I do…). Aside from them?  I don’t know too many users – even power users – who need more than 8gb of RAM ever, not even occasionally.  For them (like myself) I would say that this is the device for you.

If you are in the Greater Toronto Area come down to the Microsoft Store at Square One or Yorkdale Malls to check it out! :)

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!