The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

Archive for May, 2012

WIM2VHD using a PowerShell script (plus 2 more, WIMINFO and MakeVM-Diff scripts)

Posted by Mikael Nystrom on May 7, 2012

The Story

When using Hyper-V you need a VHD, so the correct way for creating a VHD is to use MDT 2012 (Lite Touch) and I do that for my production servers, but in some cases you do not have the deployment solution in a pocket, you just need the standard wim file converted into a bootable VHD file so you can use that as a template. Then when you have the template created you also need to be able to build new machines using that reference image and clicking in the UI is fun, for a while…

When Hyper-V was new Microsoft (a former MVP) created a VB script called WIM2VHD that I used all the time, a very nice script I think, but in Windows 8 we have all that stuff inside the OS and we do have a much stronger story in PowerShell

To be honest, I did create these script a while back, but today I was running a Windows Server 8 BETA Load fest and I used these scripts to build a bunch of demo machines, 2 minutes later our own staff was standing in line begging to get the scripts, so I gave them away but at the same time I thought you should also have access to them

The Solution

First of all, I’m not really a PowerShell “whiz kid”, I used to be the old “batch file” guy, but I’m converting (A nice thing is to have Niklas Goude that just happens to be an MVP in PowerShell in the organization).
Second, we need a couple of script. We need something to take a look inside a WIM, something that create a VHDX and applies the WIM to that VHDX and the last one, something that can build VMs using that ref image.

Script number 1: (wiminfo.ps1)

This script will mount the ISO image and read the content of the WIM file, this way we know what index we shall use.

Param
(
[parameter(mandatory=$true,HelpMessage="Please, I need the ISO image name, ok?")][ValidateNotNullOrEmpty()]$ISO
)
Mount-DiskImage -ImagePath $ISO
$ISOImage = Get-DiskImage -ImagePath $ISO | Get-Volume
$ISODrive = [string]$ISOImage.DriveLetter+”:”
Get-WindowsImage -ImagePath $ISODrive\sources\install.wim
Dismount-DiskImage -ImagePath $ISO

 

Script number 2: (wim2vhd.ps1)

This script will mount an ISO image, create the VHDx file, applies the WIM file to the VHDx file and then creates the BCD and dismounts everything.

Param

(

[parameter(mandatory=$true,HelpMessage="Please, I need the ISO image name, ok?")][ValidateNotNullOrEmpty()]$ISO,

[parameter(mandatory=$true,HelpMessage="Please, I need the VHDx image name, ok?")][ValidateNotNullOrEmpty()]$VHDx,

[parameter(mandatory=$true,HelpMessage="Please, I need the Index number in the Wim, ok?")][ValidateNotNullOrEmpty()]$Index,

[parameter(mandatory=$true,HelpMessage="Please, I need the Size of your VHDx, ok?")][ValidateNotNullOrEmpty()]$SizeGB

)

 

Mount-DiskImage -ImagePath $ISO

$ISOImage = Get-DiskImage -ImagePath $ISO | Get-Volume

$ISODrive = [string]$ISOImage.DriveLetter+”:”

 

$VMDisk01 = New-VHD –Path $VHDX -SizeBytes $SizeGB

Mount-DiskImage -ImagePath $VHDX

$VHDDisk = Get-DiskImage -ImagePath $VHDx | Get-Disk

$VHDDiskNumber = [string]$VHDDisk.Number

 

Initialize-Disk -Number $VHDDiskNumber -PartitionStyle MBR

$VHDDrive = New-Partition -DiskNumber $VHDDiskNumber -UseMaximumSize -AssignDriveLetter -IsActive | Format-Volume -Confirm:$false

$VHDVolume = [string]$VHDDrive.DriveLetter+”:”

 

dism.exe /apply-Image /ImageFile:$ISODrive\Sources\install.wim /index:$Index /ApplyDir:$VHDVolume\

 

BCDBoot.exe $VHDVolume\Windows /s $VHDVolume /f BIOS

 

Dismount-DiskImage -ImagePath $ISO

Dismount-DiskImage -ImagePath $VHDX

 

Script number 3: (MakeVM-Diff.ps1)

This script will create a VM in Hyper-V based on that VHDx file as a differencing file. It supports a bunch of command line parameters

Param

(

[parameter(mandatory=$true,HelpMessage="Please, provide a name.")][ValidateNotNullOrEmpty()]$VMName,

[parameter(mandatory=$true,HelpMessage="Please, provide a location.")][ValidateNotNullOrEmpty()]$VMBaseLocation,

[parameter(mandatory=$true,HelpMessage="Please, provide the amount of starting memory.")][ValidateNotNullOrEmpty()]$VMMemory,

[parameter(mandatory=$true,HelpMessage="Please, provide a RefDisk.")][ValidateNotNullOrEmpty()]$VMRefDisk,

[parameter(mandatory=$true,HelpMessage="Please, provide a Switch.")][ValidateNotNullOrEmpty()]$VMNetwork

)

 

$VMLocation = New-Item -Path “$VMBaseLocation\$VMName” -ItemType Directory -Force

$VMDiskLocation = New-Item -Path “$VMLocation\Virtual Hard Disks” -ItemType Directory -Force

$VMDisk01 = New-VHD –Path $VMDiskLocation\$VMName-OSDisk.vhdx -Differencing –ParentPath $VMRefDisk

$VMDisk02 = New-VHD –Path $VMDiskLocation\$VMName-DataDisk01.vhdx -SizeBytes 60GB

 

$VM = New-VM –Name $VMname –MemoryStartupBytes $VMMemory –VHDPath $VMDisk01.path -SwitchName $VMNetwork -Path $VMBaseLocation

Add-VMHardDiskDrive -VM $VM -Path $VMDisk02.path –ControllerType SCSI -ControllerNumber 0

Set-VM -VM $VM -DynamicMemory

 

Summary:

Now you have a solution that is capable of building a complete environment on a Windows Server 8 machine and a ISO image pretty fast.

Download Script

/mike

Posted in Uncategorized | 5 Comments »

IT Camp Sweden – Private Cloud (Agenda Windows Server 8 Beta dagen)

Posted by Mikael Nystrom on May 4, 2012

IT Camp Sweden – Private Cloud

Windows Server 8 Beta (2012) – Fokus på Hyper-V.

Den här dagen lägger vi allt fokus på Windows Server 8 Beta (eller Windows Server 2012 som den kommer att heta när den släpps) under förmiddagen går vi igenom alla nya funktioner som relaterar till Private Cloud funktioner såsom lagring, nätverk, hög tillgänglighet, virtualisering och lite till. Vi lägger helt och hållet fokus på att förstå hur det fungerar och på vilket sätt man kan använda dessa funktioner för att automatisera, förenkla och minska administration och samtidigt öka tillgänglighet och prestanda för att kunna köra större laster på mindre mängd och billigare hårdvara. Förmiddagspasset är lämpligt för alla, inte bara tekniker.

Agenda förmiddag:

09:00 – 09:30 Välkommen

Under trivsamma former bjuder vi så klart på en enklare frukost och lite trevligt mingel med Ola, Micke och andra kompetenta personer inom området. Du har då chansen att ställa frågor som du vill att vi ska ta upp under dagen bland annat.


09:30 – 10:20 Windows Server 8 Beta – Del I

I första passet går vi bland annat igenom Server Manager, Installation och konfiguration av Windows Server 8 Beta, Utrullning av Windows Server 8 Beta men framför allt lägger vi ner mycket tid på den nya versionen av Hyper-V och allt nytt kring den.


10:40 – 11:50 Windows Server 8 Beta – Del II
I andra passet går vi bland annat igenom alla nya funktioner kring data lagring, nyheterna i feltoleranta system och nyheterna kring nätverk och tro mig, det är mycket nya saker att hålla reda på.

11:50 – 12:00 Tack för oss och svar på dina frågar

Vi avslutar förmiddagen genom att försöka svara på dina frågor

Vi byter sedan skepnad och växlar över till hands-on labbarna. Syftet är att du nu ska få prova hur det fungerar i verkligheten (det finns utrymme för att prova egna idéer om man vill). Du får ett enklare Lab materiel som guider dig igenom ett antal moment, men i princip bygger du upp en domän med fil lagrings tjänster, virtualisering och hantering av dessa funktioner och nu får du testa det mesta av det vi gick igenom på förmiddagen under avslappnade former. Under hela tiden finns jag och Ola där (samt förmodligen några till) som kan hjälpa dig med dina frågor och funderingar på hur det är tänkt och vad man kan göra med de nya funktionerna. Du kommer att installera, konfigurerara och använda i huvudsak följande komponenter:

  • Referens Image
  • DHCP (redundant)
  • DNS
  • Storage Pools
  • Virtual Disks
  • Hyper-V
  • Failover Cluster
  • PowerShell
  • Multi Server Management

Agendan för eftermiddagen ser ut som följer:

12:30 – 16:00 Hands On Lab – Windows Server 8 Beta
Under detta block labbar du tillsammans med en “lab-partner” i en servermiljö via remote desktop (glöm inte att ta med en egen dator som kör Windows XP eller bättre gärna uppdaterad och med ett antivirus program installerat). Fika kommer att finnas tillgängligt under del av eftermiddagen

16:00 – 16:30 Avslutning
Vi tackar för oss och svarar på de sista frågorna.

Anmälan – https://msevents.microsoft.com/cui/EventDetail.aspx?culture=sv-SE&EventID=1032511416&IO=GdKZMz40g/Zi2jGEBbMuUg%3d%3d&goback=%2Egde_4343025_member_110049359

Facebook – http://www.facebook.com/technetsweden#!/events/217603188340347/



Posted in Uncategorized | Leave a Comment »

Modelalias User Exit for Microsoft Deployment Toolkit 2010/2012

Posted by Mikael Nystrom on May 1, 2012

No, I did not create this script, I think this has been around for a long time, somewhere around 2007 and correct me if I’m wrong but I believe it was Ben Hunter that started this back in the days. I have then seen this at the Deployment Guys and various other TechNet sites I did some updates to it since I do a lot of OS deployment in virtual environments, VirtualBox, VMware, Xen and of course Hyper-V. In MDT 2012 they spot most of this with the following information but in some cases you need a bit ore, and you need to be able to modify it to

So Credit goes to Microsoft, Ben Hunter and “The Deployment Guys” (and I’m sure Michael Niehaus has been involved too, so credits for him as well)

Using the Modelalias User Exit script in the Virtual World

In MDT 2012 they have bumped up the information you get from the ZTIGather script, below is the most important information we get from it. But sometimes we need more, but before we get into that, check out the list below. Notice the two last Hyper-V examples, we have the same info returned but that is not the same version of the Hypervisor.

What do you get directly from MDT 2012 s virtualization information?

Here is the result you get during the inventory when running on a VMWare ESXI or VMware Workstation

  • Property IsHypervisorRunning is now = True
  • Property IsVM is now = True
  • Property VMPlatform is now = VMware

Here is the result you get during the inventory when running on a VirtualBox

  • Property IsHypervisorRunning is now = False
  • Property IsVM is now = True
  • Property VMPlatform is now = VirtualBox

Here is the result you get during the inventory when running on a Xen

  • Property IsHypervisorRunning is now = True
  • Property IsVM is now = True
  • Property VMPlatform is now = Xen

Here is the result you get during the inventory when running on Hyper-V (2008 R2)

  • Property IsHypervisorRunning is now = True
  • Property IsVM is now = True
  • Property VMPlatform is now = Hyper-V

Here is the result you get during the inventory when running on Hyper-V (2012 BETA)

  • Property IsHypervisorRunning is now = True
  • Property IsVM is now = True
  • Property VMPlatform is now = Hyper-V

There are more info that we will get in MDT around virtualization, here is the complete information around virtualization for a Hyper-V guest OS

  • Property IsHypervisorRunning is now = True
  • Property SupportsVT is now = False
  • Property SupportsNX is now = True
  • Property Supports64Bit is now = True
  • Property SupportsHyperVRole is now = False
  • Property VMHost is now = IBL04.tslab.net
  • Property VMName is now = TESTHV20
  • Property IsVM is now = True
  • Property VMPlatform is now = Hyper-V

As you can see we also get the hostname and VMname, but only if the IC’s are loaded and they are not loaded by default in WinPE, but a friend of mine banged his head against the keyboard for a while and here is the answer…

Is this ok?

This is mostly ok and fine, but sometimes I really need to know what version of Hyper-V (or other platform) it is and at the same time I would like to support and handle the different naming standards that all vendors has and translate it all to one new property called ModelAlias. Then I can use ModelAlias instead of Model, since I can tweak, twist and bend whatever the OEM’s try to do I can translate it to something that is easy to handle. ModealAlias has been one of the easy ways to deal with Lenovo’s interesting model naming. They use 4+3 digits as model, the first 4 is the real model and the rest is the “unique” build, like unique keyboards and such (things that matters outside the OS deployment world), but for me the same driver is going to be installed even if the keyboard is in Swedish…

If you look at the last example, you will see that we get the same result for Hyper-V in all releases, well that’s “ok”, but the issue is that If I need to install the Integration Components I need to know what version to install to be supported and optimized. So by using the ModelAlias userexit script in MDT (Works in both LiteTouch and in ZeroTouch) the script will examine the bios version (and other information if you need to) and determine the version. So if we take a peek into the script it looks like this for the Hyper-V part.

As you can see BIOS version VRTUAL – 3000919 will give me ModelAlias=Hyperv2008R2 and BIOS version VRTUAL – 9001114 will give me ModelAlias Hyper-V2012BETA

Using the Modelalias User Exit script in the Physical World

Here is another example on how to use this, I was deploying servers not long ago and I was using MDT 2010 LiteTouch. I handle drivers using %make%\%model% in most cases but in this case that was kind of tricky. The reason, well IBM has some fancy characters in the model string (like -[]-), not really easy to use as a path. J

As you can see they have —[HS22]— as model name and after using the userexit script it will be converted into IBMHS22 and that is a bit easier to handle as part of a file path.

Here is one other example for a HP Compaq 8240. HP has a bunch of “different” 8240’s, but from my perspective it is just the same when it comes to drivers and apps, so we convert them into something more useful, like this

Here you can see the real model name being “HP Compaq nw8240 (PY442EA#AK8)” and after a translation it will be just “HP Compaq nw8240″ instead, easier to handle, easier to have as a path in MDT

How do you use the UserExit script?

This is the easy part, just download it, unpack it and save it in the scripts folder in MDT. Then you modify the customsettings.ini to use the script like this:

[Settings]
Priority=SetModelAlias, ModelAlias, Default
Properties= ModelAlias

[SetModelAlias]
UserExit=ModelAliasExit.vbs
ModelAlias=#SetModelAlias()#

[Hyper-V2008R2]
MandatoryApplications001=<GUIDNumberOFApplicationInLTI>

[Hyper-V2012BETA]
MandatoryApplications001=<GUIDNumberOFApplicationInLTI>

(If you are using SCCM you will the use Packages or Application name, but it works the same)

When you run ZTIGather.wsf you can see the result like this on a Windows Server 2012 BETA

You can download the ModelAlias.vbs script here

Here is some links to older versions of the script:

The Deployment Guys

Ben Hunters Blog

/mike

Posted in Deployment, Hyper-V, Lite Touch, MDT, SCCM | Tagged: , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 3,866 other followers