The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

Archive for November, 2010

Quick and Dirty – Easy Script based VM creation in Hyper-V

Posted by Mikael Nystrom on November 22, 2010

Now, I have to admit that I’m not a guru on PowerShell (Thomas Lee is one of these strange “creatures” that master PowerShell way better than I do), but if I can make it work, so can you. In my work I need to create VMs based on Hyper-V often and fast so I started a bit of thinking, what do I need to make in a way I think is ok…hmmm…. I need:

  • Something that can convert the install.wim file from the DVD into a VHD with the correct settings
  • Something that then can build a VM using differencing disk

Let me just explain this shortly, the reason for converting WIM to VHD is simple, even if it is funny to install Windows it do take some time. I could have one image, but I would like the possibility to do this in a way that can be repeated and since the source is a DVD I will base my toolset on that. The reason for using differencing disks is simply space, I have in many cases 50-60 VMs on my laptop. So differencing disks are a parent-child related disk, I only create one reference image and then a create one difference disk for each VM.

So, fine, this can of course be done with out any scripts at all, but hey the WIM to VHD are some step to do manually and using Hyper-V manager is also possible, but I don’t have that time.

So, the first tool is VIM2VHD (I did a post on that sometime back – http://itbloggen.se/cs/blogs/micke/archive/2010/08/25/using-wim2vhd-to-create-reference-images-for-hyper-v.aspx)

The second tool/script we need is on CodePlex, go to http://pshyperv.codeplex.com/ and download both the PsHyper-V Install.ZIP AND the PSHyperV-R2 documentation. Install PSHyper-V using the installer and we have almost everything we need (WIM2VHD does require some tools from WAIK, so if you have not done it, download and install The Windows® Automated Installation Kit (AIK) for Windows® 7 – http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=696dd665-9f76-4177-a811-39c26d3b3b34)

Now, here is the command line to create a reference image based on VHD from the WIM file:

cscript WIM2VHD.wsf /wim:”C:\MDTLab\Operating Systems\Windows Server 2008 R2 x64 RTM\sources\install.wim” /sku:SERVERENTERPRISE /unattend:”c:\tools\wim2vhd\Unattend – US.xml”

It takes about 6-8 minutes and then my VHD’s is done, moving on to the next step

Since I’m “old” I still use the CMD prompt, So I did batch file with parameters that will be passed into powershell, so lets look at the batch file first:

powershell -ExecutionPolicy RemoteSigned -file bvm.ps1 %1 %2 %3 %4 %5

Really exiting :-) , so this cmd file is called mvm.cmd (MakeVM) and when used correctly it looks like this:

First parameter = Location of VM, format is E:\VMs
Second parameter = Name of VM, format is MJ01
Third parameter = Memory, format is 1024 (in Megabyte)
Fourth parameter = Network, format is LAN (name of network)
Fifth parameter = ParentVHD for the OS disk, format is c:\Ref\W2K8r2x64.vhd

mvm.cmd E:\VM MIKE001 1024 LAN c:\Ref\W2K8r2x64.vhd

So, running that command will in this case build a VM called MIKE001 with 1GB of ram, connected to the network called LAB using a child disk based on the parent c:\ref\w2k8r2x64.vhd, place it in E:\VM and fire it up. I know perfectly well that I can do everything from within powershell, but I still prefer to do this from the cmd prompt. Running this takes less then 30 seconds and that’s ok. Now we need to see how the powershell script looks like and here it is:

import-module “c:\Program Files\modules\HyperV\HyperV.psd1″
$VMLOC = $args[0]
$VMNAME = $args[1]
$VMMEM = $args[2]
$VMNET = $args[3]
$VMSRC = $args[4]
$VM = New-VM         -Name $VMNAME -Path $VMLOC
Set-VMCPUCount       -VM   $VM -CPUCount 1
Set-VMMemory         -VM   $VM -Memory $VMMEM
Add-VMNIC            -VM   $VM -VirtualSwitch $VMNET
Add-VMSCSIController -VM   $VM -name “SCSI Controller”
$Disk1 = New-VHD     -VHDPaths $VMLOC\$VMNAME-disk1.vhd -ParentVHDPath $VMSRC -Verbose -Wait
$Disk2 = New-VHD     -VHDPaths $VMLOC\$VMNAME-disk2.vhd -Size 146gb -Verbose -Wait
Add-VMDisk           -VM   $VM -ControllerID 0 -LUN 0 -Path $Disk1
Add-VMDisk           -VM   $VM -ControllerID 0 -LUN 0 -Path $Disk2 -SCSI
Add-VMDisk           -VM   $VM -controllerID 1 -lun 1 “C:\MEDIA-TSLAB-LTI\LiteTouchMedia.iso” -DVD
Start-VM             -VM   $VM

As you can see it is “almost” readable :-) , this template will create a VM based on what I explained before, but it will also create a blank VHD (dynamic) on the first SCSI and it will also attach the LiteTouchMedia.ISO and the reason for that is simple, on that media I have a bunch of Post-OS Configuration tasks, so to be honest, my unattened.xml file will fire up the LiteTouch wizard and then I can select witch Post OS task I would like to run, something like DC, SQL Server, Deployment Server, TS or something like that

So, here is something else to try, fire up powershell, execute import-module “c:\Program Files\modules\HyperV\HyperV.psd1″ and try this 4 different commands:

    • get-command -module HyperV
      • now you can see that there are some commands in that module :-)
    • get-command -module Hyperv| get-help | format-table name,synopsis –auto
      • Much better, thank you
    • Show-Hypervmenu
      • a nice little menu, handy when in core server…
    • Get-VMBuildScript
      • with this you can create a reversed build script, very handy backup of the configuration

/mike
MVP – Setup/Deployment

Posted in Deployment, Hyper-V, TechEd | Leave a Comment »

Get rid of the EU browser Choice in a Task Sequence

Posted by Mikael Nystrom on November 5, 2010

 

Ok, so, no this is not a new cool thing, this is just boring but i hate when I miss it. Let me give you an example here. So, I’m supposed to build a reference image for a customer, fine no problem, I import OS, create a TS, configure, update, well you know the drill. Deploy the reference task sequence to a virtual machine, wait and then wait. Import, create a new task sequence and deploy to the real machine, logon and there it is. The most hated object on the planet, the “beeeeeeeeeeeeeeeeeeeeeeeep” “EU Browser Choice” (I’m sorry, but I don’t get the point really, in most of my customers network no one is a local admin, hello? they cant “choose” anyway…)

So, how to avoid it, well you can either block it from being installed. The “blocking” could be really easy if you use your own WSUS and you can manage to fix it there, but that’s not always the case, so we can kill it after it has been installed, and one of the easiest way is to add a reg key, most blog posts I have seen on the subject explain how to “click”, well in a task sequence it is kind of tricky to click, so here is the command line you need to add as a “Run Command” in the task sequence:

 reg.exe add HKLM\Software\BrowserChoice /v Enable /t REG_DWORD /d 0 /f

And here you can se a picture on how it looks in action

image

/mike

Posted in Uncategorized | Leave a Comment »

Tech Ed 2010 EMEA

Posted by Mikael Nystrom on November 1, 2010

Hi, I’m in full prepare “mode” for TechEd EMEA. For some reasons I have 6 sessions this year (My friend Johan has 7) and most of them Deployment. Here is the list:

  • PRC07 – Experience a REAL Windows 7 Deployment.
    • A full day of Windows 7 deployment, it cannot be more fun then this…
    • Date: Monday November 8
    • Time: 09:00-03:30
  • WCL310 – Choosing the Right Deployment Tool
    • A session with me and Johan Arwidmark
    • Date: Tuesday November 9
    • Time: 09:00-10:00
  • WCL306-IS – Top Deployment Issues With Answers From Experts
    • An interactive session with me and Johan Arwidmark
    • Date: Tuesday November 9
    • Time: 12:00-13:00
  • WCL307-IS – Certify Client Hardware for OS Deployment
    • An interactive session with me and Johan Arwidmark
    • Date: Wednesday November 10
    • Time: 09:00-10:00
  • WSV302 – Inside the LAB – Building your Own Private Cloud
    • An session with me and a bunch of computers…
    • Date: Wednesday November 10
    • Time: 12:00-13:00
  • WCL306-IS(R) – Top Deployment Issues With Answers From Experts
    • An interactive session with me and Johan Arwidmark
    • Date: Thursday November 11
    • Time: 14:30-15:30

/mike

Psst, if you attend any of my sessions, step up and say “Hi Mike, I do read your blog”, or come by, I’ll be around in the TLC (you cant miss me, short, fat and talks laud and a lot…)

Posted in TechEd | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 1,540 other followers