Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

As of right now I have a Powershell 3.0 Script Provisioning and Creating Servers. What I want to do is add an Unattended.xml to take it a step further (So I wouldn't have to get on and click next/choose disk/etc..)+ for the windows installation, How would I go about doing this?

The Script Works Fine, I just want to be able to automate the entire thing. I can read up on unattended.xml files but im mainly concerned at HOW to insert it into this script, I've read about attaching a floppy with an unattended.xml, but im not entirely sure.

#Variables
$VHDBool = 1 #Bool asking for a Non-VHD Linked VM

#Ask for Name of VM
$VMNAME = Read-Host "Enter the Name of the Server You would Like to Set up: "

#Ask for Memory Requirements of VM
[int64]$VMMEMpre = Read-Host "Ok now Enter the Memory in GB you would like to allocate: (Press [Enter] for 512MB)"
if ($VMMEMpre -eq ""){$VMMEM=512MB} ; if ($VMMEMpre -eq $NULL) {$VMMEM=512MB}
[int64]$MEMALL = 1073741824
[int64]$VMMEM = $VMMEMpre * $MEMALL

#Ask for Boot Device for VM, Should be left to CD for ISO's
$VMBOOT = Read-Host "Select a Boot Device (CD, Floppy, LegacyNetworkAdapter, and IDE), Default is CD: "
if ($VMBOOT -eq ""){$VMBOOT="CD"} ; if ($VMBOOT -eq $NULL){$VMBOOT="CD"}

#Ask for path to VM File Storage
$VMSTO = Read-Host "Enter Directory to Store new Files: (c:\storage for example, Default is c:\VMfiles)"
if ($VMSTO -eq ""){$VMSTO="c:\VMfiles"} ; if ($VMSTO -eq $NULL){$VMSTO="c:\VMfiles"}

#Ask For path to store VHDX File, or NO to not link one
$VHDXLOC = Read-Host "Enter the Path to Store your VHDX File: (c:\base.vhdx for example or enter NO for NO VHD)"
if ($VHDXLOC -eq "NO") {$VHDBOOL = 0}

#Ask for HD Space (If applicable) for VHD
if ($VHDXLOC -ne "NO"){
[int64]$VMHDpre = Read-Host "Enter The Amount of Hard Disk Space you would like allocated to the VM: (Default is 40GB)"
if ($VMHDpre -eq ""){$VMHD=40GB} ; if ($VMHDpre -eq $NULL) {$VMHD=40GB}
}
[int64]$VMHD = $VMHDpre * $MEMALL

#Creates VM (With VHDX)
if ($VHDBOOL -eq 1){
New-VM -Name $VMNAME -MemoryStartupBytes $VMMEM -BootDevice $VMBOOT -path $VMSTO -NewVHDSizeBytes $VMHD –NewVHDPath $VHDXLOC}
#Creates VM (Without VHDX)
if ($VHDBOOL -eq 0){
New-VM -Name $VMNAME -MemoryStartupBytes $VMMEM -BootDevice $VMBOOT -path $VMSTO –NoVHD}

#Ask for Location of ISO
$ISOLOC = Read-Host "Enter the Location of the ISO you would Like to Install: (c:\ISOFILE\Windows_NAME.iso)"

#Installs ISO Via Location
Set-VMDvdDrive -VMName $VMNAME -Path $ISOLOC

#Start the Server
Start-VM -Name $VMNAME
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I think it would be simplest to create the VHD and the VM separately. Then, before you boot the VM, mount the VHD and place your unattend.xml file on it. (Mount-vhd is the cmdlet you want.) Then dismount the VHD and attach it to the VM as the last part of VM creation.

You can do the same with a virtual floppy image, but it's a little more complicated since there's no local-mount option for that and because it just adds to the number of virtual disk images you're dealing with.

After you've put your unattend file on the VHD, then you can dismount the VHD with the "dismount-vhd" cmdlet. Then attach it to the VM you created with the "add-vmharddiskdrive" cmdlet.

share|improve this answer
    
How do I do them separately? Im still a bit confused at what a VHD is....is it shared by ALL VM's or just one? and how are they linked? EIther way, do I literally just move the unattended.xml onto the VHD? I guess Im a bit confused at what I should be changing on my script. Also do I mount the VHD to a specific VM.....or just to a Computer im keeping the VM's on through Hyper V? –  Mercfh Mar 7 '13 at 17:55
2  
A VHD is a file that contains the data that will be perceived by the VM as a disk. They are not shared between your VMs. Each VM has its own. (There are ways of sharing a base image between multiple VMs, but that's a more advanced topic.) You can mount the VHD file as a disk on any machine, whether it's a VM or not. The example I gave was assuming that you would mount it on the machine running the script, at least temporarily. I've also added some detail to the answer. –  Jake Oshins Mar 8 '13 at 21:32
    
Awesome, thanks for the info! Where would I put the actual unattend file though? –  Mercfh Mar 8 '13 at 21:37
1  
You'd format the disk presented by the VHD, probably with NTFS. And then you'd put the unattend file at the root of that file system. –  Jake Oshins Mar 9 '13 at 23:05
add comment

The answer I used to this question is a script I found that would create ISO files. When I would attach a VHD with the unattend.xml to the VM, it wouldn't use it. When I add a 2nd DVD to the VM, it takes it just fine.

The idea for the project I'm working on is to start with a bare metal box, and a flash drive w/ Hyper-V 2012, and Win2012, my script, and a config.xml.

The script takes the VM config out of the XML, builds the first one, inserts firstlogon commands based on hostname, and then moves on to the next VM. I'll be releasing it on TechNet once I'm done with it, but the ISO creation script isn't mine. If you look on TechNet under my name, I've linked it there.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.