Speed Lab – Bulk create Hyper-V Virtual Machines with Windows PowerShell

Hyper-V gives you an environment to quickly and efficiently run test configurations, which has made it a popular lab environment. The only catch is, you need to create and configure virtual machines (VMs) on a regular basis.
Whether you need to test new or standardized server setups, creating virtual machines is still a boring.

If you’re looking for an easy way to build Hyper-V images, Windows PowerShell scripts are a viable solution. The extent to which you can customize Windows PowerShell and its flexible command structure makes it suitable for any environment. When combined with an automated or unattended setup strategy, virtually any computer configuration is possible. Underneath the examples for Generation 1 and Generation 2 machines.

Prequisits;
-Path E:\VMs exist
-The ISO file and location is in place
-The Virtual network “Internal” is implemented in Hyper-V

*************Bulk create generation 2 virtual machines**************

$VMLocation = "E:\VMs"
$VMISO = "E:\ISO\W2012R2.iso"
$VMNetwork = "Internal"

# Create DC01
$VMName = "DC01"
$VMMemory = 1024MB
$VMDiskSize = 40GB
New-VM -Name $VMName -Generation 2 -BootDevice CD -MemoryStartupBytes $VMMemory -SwitchName $VMNetwork -Path $VMLocation -NoVHD -Verbose
New-VHD -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -SizeBytes $VMDiskSize -Verbose
Add-VMHardDiskDrive -VMName $VMName -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -Verbose
Set-VMDvdDrive -VMName $VMName -Path $VMISO -Verbose

# Create CM01
$VMName = "CM01"
$VMMemory = 6144MB
$VMDiskSize = 300GB
New-VM -Name $VMName -Generation 2 -BootDevice CD -MemoryStartupBytes $VMMemory -SwitchName $VMNetwork -Path $VMLocation -NoVHD -Verbose
New-VHD -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -SizeBytes $VMDiskSize -Verbose
Add-VMHardDiskDrive -VMName $VMName -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -Verbose
Set-VMDvdDrive -VMName $VMName -Path $VMISO -Verbose

*************Bulk create generation 1 virtual machines**************

$VMLocation = "E:\VMs"
$VMISO = "E:\ISO\W2012R2.iso"
$VMNetwork = "Internal"

# Create DC01
$VMName = "DC01"
$VMMemory = 1024MB
$VMDiskSize = 40GB
New-VM -Name $VMName -BootDevice CD -MemoryStartupBytes $VMMemory -SwitchName $VMNetwork -Path $VMLocation -NoVHD -Verbose
New-VHD -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -SizeBytes $VMDiskSize -Verbose
Add-VMHardDiskDrive -VMName $VMName -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -Verbose
Set-VMDvdDrive -VMName $VMName -Path $VMISO -Verbose

# Create CM01
$VMName = "CM01"
$VMMemory = 6144MB
$VMDiskSize = 300GB
New-VM -Name $VMName -BootDevice CD -MemoryStartupBytes $VMMemory -SwitchName $VMNetwork -Path $VMLocation -NoVHD -Verbose
New-VHD -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -SizeBytes $VMDiskSize -Verbose
Add-VMHardDiskDrive -VMName $VMName -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -Verbose
Set-VMDvdDrive -VMName $VMName -Path $VMISO -Verbose

Before you implement Hyper-V R2 replication; tips, tricks, does and dont’s

This blog post describes how Hyper-V replica can put into place and what are the pro’s and cons for implementing Hyper-V replica. Futhermore this blog posts describes the things to consider when replicating SharePoint, SQL and Active Directory.

Hyper-V replica is an Hyper-V role; introduced in Windows 2012 and enhanced in Windows 2012 R2.
Hyper-V replica can asynchronously replicate a selected VM running at a primary site to a designated replica site across LAN/WAN based on the SMB 3.0 Protocol. This is possible without any need for clustered or central storage.

The only thing you need is local storage on both sites of disaster recovery (DR) site and the primary site (PR).

Hyper-V Replica

Why Hyper-V replication?
-Affordable in-box business continuity and disaster recovery
-Replication frequencies of 5 minutes (Configurable from 30 seconds, 5 minutes or 15 minutes in R2)
-Secure replication across network
-Agnostic of hardware on either site
-No need for other virtual machine replication technologies
-Automatic handling of live migration
-Simple configuration and management

New In Windows 2012 R2
-Replication in 2012 R2 is near synchronic
-Possibility to do test failovers
-Configure TCP settings (before bringing machine online) when brining to other side (inject as part of VMConfig) Extended Replication
-Once a VM has been successfully replicated to the replica site, replica can be replicated to a 3rd location
-Chained Replication
-Extended Replica contents match the original replication contents
-Extended Replica replication frequencies can differ from original replica
-Useful for scenarios such as SMB -> Service Provider -> Service Provider DR Site
Hyper-V Replication DR Site

Things to consider
At the moment there are some caveheats on this solution because Hyper-V replica is an a-synchronic replication some products need special attention (Exchange, SQL and AD).

-Windows Server 2012 Domain Controllers
To replicate Domain Controllers Windows 2012 is required. Windows Server 2012 Hyper-V introduces VM-GenerationID (VMGenID). VMGenID provides a way for the hypervisor to communicate to the guest OS when significant changes have occurred. For example, the hypervisor can communicate to a virtualized DC that a restore from snapshot has occurred (Hyper-V snapshot restore technology, not backup restore). AD DS in Windows Server 2012 is aware of VMGenID VM technology and uses it to detect when hypervisor operations are performed, such as snapshot restore, which allows it to better protect itself. See http://technet.microsoft.com/en-us/library/dn250021.aspx for more information

No Exchange Support for Hyper-V Replica
Exchange does not support the Hyper-V Replica feature.  Exchange has a long history of supporting virtualisation from Exchange 2003 onwards.  It is fully supported to install Exchange 2007, 2010 or 2013 as a virtual machine on Hyper-V, but using the Hyper-V replica feature is not supported. The product team is working an a solution for this.

After doing some test the Hyper-V failover of Exchange works most of the time (6 out of 10). Therefore we are still waiting on the product group of Exchange and a good offsite backup is therefore (always) an requirement.

-SQL Support
Minimal version of SQL Server 2008 R2 on Hyper-V Replica and is only supported when the EnableWriteOrderPreservationAcrossDisks flag is set. See http://support.microsoft.com/kb/956893 for more information.

Install SCVMM 2012 SP1 on Windows 2012 with SQL 2012

Today a blog post on how to install SCVMM 2012 SP1 on Windows 2012 with SQL 2012

First of all the requirements for SCVMM 2012 SP1 on Windows server 2012
See http://technet.microsoft.com/library/gg610669.aspx for more information.

– SQL Server 2012 Enterprise, Standard (64-bit), SQL 2008 R2 (64-bit), SQL Server 2008 (64-bit) (Express is no longer supported)
– Domain account for SCVMM with local administrator rights on the SCVMM Server
– SQL Admin account to create the SCVMM Database
– Windows Assessment and Deployment Kit for Windows 8
– Minimal 2048 MB of RAM required

1. On the SCVMM Server – Install the WADK (Windows Assessment and Deployment Kit)
In Windows 2012 you no longer use WAIK, we’re now on WADK for Windows 8.
– Go to http://go.microsoft.com/fwlink/?LinkID=252874 and download the ADK Setup.
– Run the ADKSetup.exe as an administrator

– I left the path’s default and choose Next
– Choose if you want to join CEIP and choose Next
Accept the Licence Agreement and choose Accept
– Check Deployment Tools and Windows Preinstallation Environment (Windows PE)
SCCM 2012 SP1
– Choose Next and install the Software

2. Optional – On the AD Server –
By default, VMM encrypts some data in the VMM database (for example Run As account credentials and passwords in guest operating system profiles) by using the Windows Data Protection API (DPAPI). The encryption of this data is tied to the specific computer on which VMM is installed and the service account used by VMM. Therefore, if you need to move your VMM installation to another computer, the encrypted data will not be retained.
Distributed key management, however, stores the encryption keys in AD DS. Therefore, if you need to move your VMM installation to another computer, the encrypted data will be retained, because the other computer will have access to the encryption keys in AD DS.
If you want to use this look at http://technet.microsoft.com/en-US/library/gg697604.aspx

3. On the SCVMM Server – Install IIS Requirements
Open Server Manager
– Select Add Roles and features, click Next
– Choose Role Based or Feature based installation
– Select the local server, Next
Open Web Server (IIS) and ADD select the following features

Common
Default Document
Directory Browsing
HTTP Errors
Static Content

Health and Diagnostics
HTTP logging
Performance
Static Content

Security
Request Filtering
Windows Authentication

Management Tools
IIS Management Console
IIS 6 Management Compatibility
IIS 6 Metabase Compatibility
IIS Management Scripts and Tools
Management Service

4. On the SCVMM Server – Install SCVMM
Go to the SCVMM CD and startup install SCVMM
– Choose VMM Management Server and VMM Console and click Next
Setup 1 SCVMM
– Fill in the name, organization name and product key and hit Next
– Fill in the forms and hit Next for a few times 🙂
– Turn on the Windows Update Feature
Windows Update
– Choose the installation directory (we used D:\Program Files\Microsoft System Center 2012\Virtual Machine Manager)
– Set the Database Configuration
ScreenHunter_192 Jan. 28 12.37
– Type the SCVMM Service account and password and choose Next.
SCVMM Password
– Leave the ports default and choose Next
– On the library configuration page, leave default and also choose Next and let the installation finish

– After the installation is finished check the event logs and update the server with the latest SCVMM rollups.
Reboot the server

After the reboot run Windows Update for the cumulative updates for SCVMM 2012 SP1.
That’s it!