Enable VT and install the Hyper-V Role with PowerShell Remoting

Posted: 07/08/2011 in PowerShell, Virtualisation

I had a situation where I needed to enable the Virtualisation Technology (VT) across a bunch of Dell servers and then install the Hyper-V role. It turned out to be much simpler than I originally thought thanks in part to PowerShell remoting and Dells omconfig.

Dell give you the option to change BIOS configuration from the command line, for example to enable the CPU VT:


omconfig chassis biossetup attribute=cpuvt setting=enabled

In addition to the above I would also need to install the Hyper-V role:

Import-Module ServerManager ; Add-WindowsFeature Hyper-V

This can be combined into a PowerShell remote command like so ($allServers is an array of all the server host names I want to execute the command against):

icm -ComputerName $allServers -ScriptBlock { omconfig chassis biossetup attribute=cpuvt setting=enabled ; Import-Module ServerManager ; Add-WindowsFeature Hyper-V }

Next I needed to create a software virtual switch, for this I used a script from

http://blogs.technet.com/b/virtualization/archive/2008/05/26/hyper-v-wmi-using-powershell-scripts-part-5.aspx :

$VirtualSwitchService = get-wmiobject -class "Msvm_VirtualSwitchManagementService" -namespace "root\virtualization"
$ReturnObject = $VirtualSwitchService.CreateSwitch([guid]::NewGuid().ToString(), "DELL NETWORK TEAM - Virtual Network", "1024","")

#Create New Virtual Switch
$CreatedSwitch = [WMI]$ReturnObject.CreatedVirtualSwitch

#Create Internal Switch Port
$ReturnObject = $VirtualSwitchService.CreateSwitchPort($CreatedSwitch, [guid]::NewGuid().ToString(), "InternalSwitchPort", "")
$InternalSwitchPort = [WMI]$ReturnObject.CreatedSwitchPort

#Create External Switch Port
$ReturnObject = $VirtualSwitchService.CreateSwitchPort($CreatedSwitch, [guid]::NewGuid().ToString(), "ExternalSwitchPort", "")
$ExternalSwitchPort = [WMI]$ReturnObject.CreatedSwitchPort

$ExternalNic = get-wmiobject -namespace "root\virtualization" -Query "Select * From Msvm_ExternalEthernetPort WHERE IsBound=False" | ? { $_.Name -eq 'BASP Virtual Adapter'}

#Call SetupSwitch
$Job = $VirtualSwitchService.SetupSwitch($ExternalSwitchPort, $InternalSwitchPort, $ExternalNic, [guid]::NewGuid().ToString(), "InternalEthernetPort")
while (([WMI]$Job.Job.JobState -eq 2) -or ([WMI]$Job.Job.JobState -eq 3) -or ([WMI]$Job.Job.JobState -eq 4)) {Start-Sleep -m 100}
[WMI]$Job.Job

And finally reboot them all (they actually reboot twice as part of the Hypervisor installtion):

icm -ComputerName $allServers -ScriptBlock { Restart-Computer -Force }

With the above I managed to enable and install Hyper-V across 70 severs simultaneously with less than a couple of hours of effort, nice!

Kind Regards,

jfrmilner

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s