Want to deploy virtual machines in a hurry? PowerShell is your friend

Improve your automation

Sometimes you just need to do things fast. Being able to deploy new virtual machines rapidly is a necessity when you are prototyping proof of concepts, running virtual desktop deployments or when you just need to roll out new virtual machines in a lab environment.

Let’s face it, unless you have written PowerShell scripts to replace all the boring yet essential jobs you do every day, then you are nowhere near good enough at automation.

So let’s take a look at how you can get better in a hurry by scripting the creation of your Hyper-V virtual machines.  

Getting started

This article contains some moderately complex code and concepts. It also requires you to enable PowerShell to configure the servers – or clients – remotely after you have deployed them.

Windows Server 2012 has PowerShell remoting enabled by default, but if you are running 2008r2 then you will need to Google how to enable it manually.

To deploy these scripts in your environment you will need:  

  •  At least one Windows Server 2012 running Hyper-V 3
  •  A fully configured domain controller (DC)
  •  Dynamic Host Configuration Protocol (DHCP) (either in your DC or routing/switching equipment)
  •  A Hyper-V VHDX hard drive file that will act as the golden image for deployments
  •  A basic knowledge of the PowerShell scripting language

Step 1: Making your golden image

This is the longest and most involved step in the process. (Currently the capability to support Windows clients in IaaS for Azure is available only in test dev and only for MSDN subscriptions.)

Chances are that the first few times you do it you won’t get it exactly right, but getting it right is important. A well-crafted golden image means that post deployment you can simply launch the virtual machine.

A golden image is basically just a virtual machine that contains the operating system and anything else you need. Once you have finished installing and configuring it you need to prepare it for cloning using SysPrep.exe.

I currently have seven GIs in my virtual machine cache ready to deploy as needed.

1.Windows 7 x64 [vanilla]: a base image that has only had AV and Windows updates installed.

2. Windows 7 x64 [VDI]: my VDI testing base image with Office and assorted productivity apps pre-installed and configured.

3. Windows 8.1 x64 [vanilla]: a base image that has only AV and Windows updates installed.

4. Windows 8.1 x64 [VDI]: my VDI testing base image with Office and assorted productivity apps pre-installed and configured.

5. Server 2012r2 [vanilla]: a base image with Windows updates installed but no other services.

6. Server 2012r2 [storage]: a Server 2012 instance preconfigured to run as a storage server.

7. Server 2012r2 [RDSH]: a Server 2012 instance preconfigured for RDSH.

Next page: Gold standard

Similar topics

Other stories you might like

  • Heart FM's borkfast show – a fine way to start your day

    Jamie and Amanda have a new co-presenter to contend with

    There can be few things worse than Microsoft Windows elbowing itself into a presenting partnership, as seen in this digital signage for the Heart breakfast show.

    For those unfamiliar with the station, Heart is a UK national broadcaster with Global as its parent. It currently consists of a dozen or so regional stations with a number of shows broadcast nationally. Including a perky breakfast show featuring former Live and Kicking presenter Jamie Theakston and Britain's Got Talent judge, Amanda Holden.

    Continue reading
  • Think your phone is snooping on you? Hold my beer, says basic physics

    Information wants to be free, and it's making its escape

    Opinion Forget the Singularity. That modern myth where AI learns to improve itself in an exponential feedback loop towards evil godhood ain't gonna happen. Spacetime itself sets hard limits on how fast information can be gathered and processed, no matter how clever you are.

    What we should expect in its place is the robot panopticon, a relatively dumb system with near-divine powers of perception. That's something the same laws of physics that prevent the Godbot practically guarantee. The latest foreshadowing of mankind's fate? The Ethernet cable.

    By itself, last week's story of a researcher picking up and decoding the unintended wireless emissions of an Ethernet cable is mildly interesting. It was the most labby of lab-based demos, with every possible tweak applied to maximise the chances of it working. It's not even as if it's a new discovery. The effect and its security implications have been known since the Second World War, when Bell Labs demonstrated to the US Army that a wired teleprinter encoder called SIGTOT was vulnerable. It could be monitored at a distance and the unencrypted messages extracted by the radio pulses it gave off in operation.

    Continue reading
  • What do you mean you gave the boss THAT version of the report? Oh, ****ing ****balls

    Say what you mean

    NSFW Who, Me? Ever written that angry email and accidentally hit send instead of delete? Take a trip back to the 1990s equivalent with a slightly NSFW Who, Me?

    Our story, from "Matt", flings us back the best part of 30 years to an era when mobile telephones were the preserve of the young, upwardly mobile professionals and fixed lines ruled the roost for more than just your senior relatives.

    Back then, Matt was working for a UK-based fixed-line telephone operator. He was dealing with a telephone exchange which served a relatively large town. "I ran a reasonably ordinary, read-only command to interrogate a specific setting," he told us.

    Continue reading

Biting the hand that feeds IT © 1998–2021