During the TechEd 2014 NA preconference earlier today, I demonstrated how to deploy a VM fully unattended using a PowerShell script. A few people asked for the script being used so here it is.
Requirements, for this script to work, you need to have a MDT 2013 Lite Touch deployment share, configured for full automation.
In my environment the Bootstrap.ini looks like this:
[Settings]
Priority=Default
[Default]
DeployRoot=\\MDT01\MDTBuildLab$
UserDomain=VIAMONSTRA
UserID=MDT_BA
UserPassword=P@ssw0rd
SkipBDDWelcome=YES
The CustomSettings.ini looks like this:
[Settings]
Priority=Default
[Default]
_SMSTSORGNAME=ViaMonstra
UserDataLocation=NONE
DoCapture=YES
ComputerBackupLocation=\\MDT01\MDTBuildLab$\Captures
BackupFile=%TaskSequenceID%#"(" & day(date) & "-" & month(date) & "-" & year(date) & ")"#.wim
TaskSequenceID=REFW81X64-001
OSInstall=Y
AdminPassword=P@ssw0rd
TimeZoneName=Pacific Standard Time
JoinWorkgroup=WORKGROUP
HideShell=YES
FinishAction=SHUTDOWN
DoNotCreateExtraPartition=YES
WSUSServer=mdt01.corp.viamonstra.com:8530
ApplyGPOPack=NO
SkipAdminPassword=YES
SkipProductKey=YES
SkipComputerName=YES
SkipDomainMembership=YES
SkipUserData=YES
SkipLocaleSelection=YES
SkipTaskSequence=YES
SkipTimeZone=YES
SkipApplications=YES
SkipBitLocker=YES
SkipSummary=YES
SkipRoles=YES
SkipCapture=YES
SkipFinalSummary=YES
Then, to automate the deployment of the virtual machine, I run this PowerShell script:
$VMLocation = "D:\VMs"
$VMISO = "C:\ISO\MDT Build Lab x64.iso"
$VMNetwork = "Internal"
# Create REF001
$VMName = "REF001"
$VMMemory = 1024MB
$VMDiskSize = 60GB
New-VM -Name $VMName -BootDevice CD -MemoryStartupBytes $VMMemory -SwitchName $VMNetwork -Path $VMLocation -NoVHD -Verbose
New-VHD -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -SizeBytes $VMDiskSize -Verbose
Add-VMHardDiskDrive -VMName $VMName -Path "$VMLocation\$VMName\Virtual Hard Disks\$VMName-Disk1.vhdx" -Verbose
Set-VMDvdDrive -VMName $VMName -Path $VMISO -Verbose
Start-VM -VMName $VMName
$VM = Get-VM -Name $VMName
while ($VM.State -ne "off")
{
write-host "The VM is still running"
sleep 20
}
Remove-VM -Name $VMName -Force
Remove-Item -Recurse -Force $VMLocation\$VMName
The above script assume you have copied the MDT 2013 boot media (ISO) to the C:\ISO folder, and named it "MDT Build Lab x64.iso"
Happy Deployment, Johan
Hi Johan.
The script Works perfect. But is there a way to automate it if i have more than one image i want to update in theis way?
Fx
Windows7
Windows_server2012
Windows8
Now i hardcode the taskswquence in the Rules tab of the deploymentshare.
Thanks for a good session at scug.dk in Teknologisk last Friday
Br
Jesper olsen
f you are using port 80 you don't need to specify the port, just WSUSServer=mdt01.corp.viamonstra.com
I have never tried using ip address only, and never will. I always make sure I have a working name resolution since so many other components rely on it.
/ Johan
Hey anyone got any insite on this from 6/24/2014?
Hey, got a question about doing my reference image. for the line:
WSUSServer=mdt01.corp.viamonstra.com:8530
Does the Wsus server have to be on port 8530? I believe ours is using port 80
Also can we do the IP only?
WSUSServer=192.168.1.1:80
Thanks.
Technically yes, but you should always start your reference image builds from the Microsoft media.
Follow these steps to create a ref image: technet.microsoft.com/en-us/library/dn744290.aspx
If you want a VHD for faster cloning later, just apply the WIM file to a VHD.
You can also have MDT deploy directly to a VHD, but then you miss the default cleanup functions that MDT does.
/ Johan
Anyway to do this same process, but with VHD instead of installing Windows from ISO? I have parent VHD and want to create a differencing disk when making reference images. I have script to create VM using differecing disk VHD, but I think MDT doesn't like this when going through Sysprep/Capture Task Sequences.
Hey, got a question about doing my reference image. for the line:
WSUSServer=mdt01.corp.viamonstra.com:8530
Does the Wsus server have to be on port 8530? I believe ours is using port 80
Also can we do the IP only?
WSUSServer=192.168.1.1:80
Thanks.
Yes, using two vCPUs will speed up the capture process.
/ Johan
I've managed to build a full environment with DC01 and MDT01 fully configured using your great Hydration pack. I did have some troubles but that was corrupt ISO files. All fixed now and working great. I am now trying to create a full VM reference image. I'm using VMWare Workstation and have the DC01 and MDT01 set to HOST only, to restrict the network and not have it conflicting. I'm booting the reference VM up using the MDT litetouch ISO that is created by MDT. If I try to boot from this, it gets an IP address but is not… Read more »
Use a staging OU (with no policies) and as a final step of the task sequence, call a web service that moves the machine into the correct OU (that has the PIV card policy assigned to it), and then add a final reboot.
/ Johan
How do you disable PIV card policy during deployment after the computer is joined to domain and recieved the policy?
in our environment we have PIV cards to log in to computers. policy is mandatory and being pushed to all computers.
this will stop MDT deployment after joinig to domain and first reboot, because the autologon will fail and even if I login with PIV thr script will not cotinue to finish installing the apps.
And thanks Ben for pointing out #23, the script has been updated 🙂
/ Johan
Yes, multiple vCPU's almost doubles the speed… I have updated the post for additional tips bumping up the speed.
Building reference images like a boss!
https://deploymentresearch.com/Research/tabid/62/EntryId/174/Building-reference-images-like-a-boss.aspx
/ Johan
One more word on this: i finally got this up & working in a RAM Disk.
However during the "Capture WIM" process my VM runs on 100% CPU, i see the imagex.exe running complete time on 100% CPU load.
So maybe it's a good idea to give the reference VM 2 CPU's instead of 1?
My "Capture WIM" is telling me that it will be running 50 minutes from now on 🙁
Johan,
line #23 could be misleading in case you do not store your vm's on d:
Can you fix that to use the Variable $VMLocation?
Cool, thanks
/ Johan
Here is my VMware version, run from the SCCM server.
#Import all the PowerCLI stuff
Add-PSSnapIn VMware.VimAutomation.Core
Add-PSSnapIn VMware.VimAutomation.Vds
cd "C:Program Files (x86)VMwareInfrastructurevSphere PowerCLIScripts"
.Initialize-PowerCLIEnvironment.ps1
#Connect to vCenter and start MDT virtual machine
Connect-VIServer -Server vcenter.network.lan
Start-VM MDT
#Wait till the MDT task sequence has finished
Do {
Start-Sleep -Seconds 600
Write-Host "Waiting"
} While ((Get-VM MDT).PowerState -eq "PoweredOn")
#Roll the MDT virtual machine back to the blank snapshot
Set-VM -VM MDT -Snapshot "Pre-OS" -Confirm:$false
#Move the captured WIM to the correct folder and import it into SCCM
Move-Item -Path 'C:DeploymentShareCapturesWindows7EntSP1x64.wim' -Destination C:PackagesOSWindows7EntSP1x64MDTWindows7EntSP1x64MDT.wim -Force -Confirm:$false
Import-Module 'C:Program Files (x86)Microsoft Configuration ManagerAdminConsolebinConfigurationManager.psd1'
Start-Sleep -Seconds 30
cd :
Update-CMDistributionPoint -OperatingSystemImageName "Windows 7 Enterprise SP1 x64 MDT"