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.
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.