In continuing with the post that I started last week, this week I focus on how I used PowerShell to install Hyper-V on Windows 8 and then create all necessary items to continue the creation of the SharePoint lab running on Hyper-V on Windows 8.
First thing, in all situations I started PowerShell as Administrator. And yes, many of this items can be done and worked on through the GUI. But, the point is how do I automate. Also, assumptions here are you have a licensed version of Windows 8, and your hardware support the use of Hyper-V.
Enabling Hyper-V using PowerShell
enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Once the above has been executed, your system will restart and Hyper-V will be enabled in the process.
Since it is now in place, how about opening PowerShell as Administrator again. Now we will configure the Virtual Switch (again, yes, we could do this from Hyper-V Manager, but the goal is to script it).
Adding Private or Internal virtual switch types
To add a private or internal switch type you will need the following:
New-VMSwitch “Internal Network” –SwitchType Internal
The key parameter in the above statement is –SwitchType, which can be followed by either Internal or Private.
Adding External virtual switch types
To add an external switch type you will do a couple of items, first get information on the available network adapters, and then create the switch attached to a specific network adapter. You will notice in order to create this the –SwitchType parameter is not used.
First, check the network adapters available.
From that output we will take the Name property/field. Then we will use that information to provision the external switch. From the example below remember to use the name that applies to your environment.
New-VMSwitch “External Network” –NetAdapterName “Local Area Connection 2”
Now, the network portion is done and ready. We will proceed to provision the VMs now.
Provisioning Virtual Machines
The statement to provision the VM will look as follows:
New-VM -Name $LabDC -Path $LabPath -MemoryStartupBytes 768MB -NewVHDPath $LabPath\$LabDC.vhdx -NewVHDSizeBytes 60GB -SwitchName $InternalNet
For simplicity and understanding I am linking here the script with the process, broken into two separate scripts, one for the creation of the External Network and the other including the Internal Network creation and the VM provision process.
Hope this helps in the process.
Create External Network