%3CLINGO-SUB%20id%3D%22lingo-sub-706564%22%20slang%3D%22en-US%22%3EThere%20is%20never%20enough%20automation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-706564%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20TechNet%20on%20Feb%2015%2C%202016%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EWhen%20I%20first%20started%20in%20IT%2C%20I%20worked%20with%20a%20team%20of%20people%20to%20do%20very%20repetitive%20tasks%20as%20a%20DBA.%26nbsp%3B%20Fortunately%2C%20a%20few%20of%20those%20people%20had%20the%20right%20idea%3A%26nbsp%3B%20With%20enough%20automation%2C%20we%20can%20eliminate%20the%20need%20for%20our%20jobs.%26nbsp%3B%20Now%20that%20might%20sound%20like%20a%20career%20mistake%2C%20but%20what%20you%20quickly%20realize%20is%20that%20if%20you%20get%20rid%20of%20the%20mundane%2C%20you%20can%20move%20on%20to%20something%20more%20interesting%20%E2%80%93%20and%20there%E2%80%99s%20always%20something%20more%20interesting.%26nbsp%3B%20After%20a%20few%20years%2C%20we%20were%20to%20that%20point%2C%20and%20then%20we%20started%20bringing%20order%20to%20PCs.%3C%2FP%3E%0A%20%20%3CP%3EFast%20forward%20a%20few%20years%20and%20the%20same%20idea%20was%20applied%20to%20MDT%3A%26nbsp%3B%20There%E2%80%99s%20no%20such%20thing%20as%20too%20much%20automation.%26nbsp%3B%20And%20even%20now%2C%20I%20still%20have%20to%20remind%20myself%20of%20that.%3C%2FP%3E%0A%20%20%3CP%3ECase%20in%20point%3A%26nbsp%3B%20I%20needed%20to%20do%20some%20larger-scale%20testing%2C%20which%20is%20great%20with%20virtual%20machines.%26nbsp%3B%20And%20since%20it%E2%80%99s%20very%20simple%20to%20create%20fully-functional%20VMs%20from%20a%20ready-to-go%2C%20patched%20VHDX%20file%20using%20PowerShell%2C%20I%20created%20those%20VMs%20in%20just%20a%20few%20minutes%20and%20let%20them%20churn%20for%20a%20while%20after%20they%20started%20out.%26nbsp%3B%20But%20it%20seemed%20like%20%E2%80%9Ctoo%20much%20work%E2%80%9D%20to%20also%20automate%20the%20configuration%20of%20those%20VMs%20%E2%80%93%20all%20I%20needed%20to%20do%20after%20all%20was%20rename%20and%20join%20a%20domain.%26nbsp%3B%20But%20instead%20of%20a%20little%20more%20PowerShell%20to%20inject%20a%20configured%20unattend.xml%20into%20each%20VM%2C%20I%20thought%20%E2%80%9Cno%2C%20I%E2%80%99ll%20do%20it%20manually%20later.%E2%80%9D%26nbsp%3B%20Well%2C%20that%20was%20a%20bad%20idea%3A%26nbsp%3B%20I%20spent%20hours%20configuring%20the%20VMs%2C%20connecting%20to%20each%20one%2C%20completing%20OOBE%2C%20logging%20in%20with%20a%20local%20account%2C%20opening%20up%20the%20computer%20settings%2C%20changing%20the%20computer%20name%2C%20joining%20the%20domain%2C%20and%20rebooting.%26nbsp%3B%20All%20because%20I%20didn%E2%80%99t%20want%20to%20spend%20an%20hour%20or%20so%20on%20a%20little%20more%20scripting.%3C%2FP%3E%0A%20%20%3CP%3EIn%20any%20case%2C%20I%20thought%20someone%20might%20be%20interested%20in%20the%20PowerShell%20script%20to%20create%20a%20batch%20of%20VMs%2C%20which%20I%20cobbled%20together%20from%20various%20other%20samples%20on%20the%20web%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CFONT%20face%3D%22Courier%20New%22%3E%20%24parentpath%20%3D%20%22E%3A%5CVMs%5C10240.x64.ClientBase.vhdx%22%20%3CBR%20%2F%3E%20%24path%20%3D%20%22E%3A%5CVMs%5C%22%20%3C%2FFONT%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CFONT%20face%3D%22Courier%20New%22%3E%20foreach%20(%24i%20in%201..20)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%24suffix%20%3D%20%24i.ToString(%22000%22)%20%3CBR%20%2F%3E%20%24vmname%20%3D%20%22CLONE-%24suffix%22%20%3C%2FFONT%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CFONT%20face%3D%22Courier%20New%22%3E%20%23create%20a%20VHDX%20%E2%80%93%20differencing%20format%20%3CBR%20%2F%3E%20%24vhdpath%20%3D%20%22%24path%5C%24vmname%20Disk%200.vhdx%22%20%3CBR%20%2F%3E%20New-VHD%20-ParentPath%20%24parentpath%20-Differencing%20-Path%20%24vhdpath%20%3C%2FFONT%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CFONT%20face%3D%22Courier%20New%22%3E%20%23Create%20the%20VM%20%3CBR%20%2F%3E%20New-VM%20-VHDPath%20%22%24vhdpath%22%20-Name%20%24vmname%20-Path%20%22%24path%22%20-SwitchName%20%22Lab%22%20-Generation%202%20%3C%2FFONT%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CFONT%20face%3D%22Courier%20New%22%3E%20%23Configure%20Dynamic%20Memory%20%3CBR%20%2F%3E%20Set-VMMemory%20-VMName%20%24vmname%20-DynamicMemoryEnabled%20%24True%20-MaximumBytes%202GB%20-MinimumBytes%201GB%20-StartupBytes%201GB%20%3C%2FFONT%3E%3C%2FP%3E%0A%20%20%3CP%3E%3CFONT%20face%3D%22Courier%20New%22%3E%20%23Start%20the%20VM%20%3CBR%20%2F%3E%20Start-VM%20%24vmname%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3C%2FFONT%3E%3C%2FP%3E%0A%20%20%3CP%3EYou%20might%20need%20to%20tweak%20it%20(with%20proper%20paths%2C%20the%20name%20of%20your%20Hyper-V%20network%20switch%2C%20etc.%26nbsp%3B%20But%20that%E2%80%99s%20the%20easy%20part.%3C%2FP%3E%0A%20%20%3CP%3ENext%20time%2C%20I%E2%80%99ll%20add%20the%20logic%20to%20inject%20an%20unattend.xml%20to%20automate%20OOBE%2C%20name%20the%20computer%2C%20and%20join%20the%20AD%20domain%E2%80%A6%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-706564%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20TechNet%20on%20Feb%2015%2C%202016%20When%20I%20first%20started%20in%20IT%2C%20I%20worked%20with%20a%20team%20of%20people%20to%20do%20very%20repetitive%20tasks%20as%20a%20DBA.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-706564%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Emichael%20niehaus%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ewindows%2010%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on TechNet on Feb 15, 2016

When I first started in IT, I worked with a team of people to do very repetitive tasks as a DBA.  Fortunately, a few of those people had the right idea:  With enough automation, we can eliminate the need for our jobs.  Now that might sound like a career mistake, but what you quickly realize is that if you get rid of the mundane, you can move on to something more interesting – and there’s always something more interesting.  After a few years, we were to that point, and then we started bringing order to PCs.

Fast forward a few years and the same idea was applied to MDT:  There’s no such thing as too much automation.  And even now, I still have to remind myself of that.

Case in point:  I needed to do some larger-scale testing, which is great with virtual machines.  And since it’s very simple to create fully-functional VMs from a ready-to-go, patched VHDX file using PowerShell, I created those VMs in just a few minutes and let them churn for a while after they started out.  But it seemed like “too much work” to also automate the configuration of those VMs – all I needed to do after all was rename and join a domain.  But instead of a little more PowerShell to inject a configured unattend.xml into each VM, I thought “no, I’ll do it manually later.”  Well, that was a bad idea:  I spent hours configuring the VMs, connecting to each one, completing OOBE, logging in with a local account, opening up the computer settings, changing the computer name, joining the domain, and rebooting.  All because I didn’t want to spend an hour or so on a little more scripting.

In any case, I thought someone might be interested in the PowerShell script to create a batch of VMs, which I cobbled together from various other samples on the web:

$parentpath = "E:\VMs\10240.x64.ClientBase.vhdx"
$path = "E:\VMs\"

foreach ($i in 1..20)
{
$suffix = $i.ToString("000")
$vmname = "CLONE-$suffix"

#create a VHDX – differencing format
$vhdpath = "$path\$vmname Disk 0.vhdx"
New-VHD -ParentPath $parentpath -Differencing -Path $vhdpath

#Create the VM
New-VM -VHDPath "$vhdpath" -Name $vmname -Path "$path" -SwitchName "Lab" -Generation 2

#Configure Dynamic Memory
Set-VMMemory -VMName $vmname -DynamicMemoryEnabled $True -MaximumBytes 2GB -MinimumBytes 1GB -StartupBytes 1GB

#Start the VM
Start-VM $vmname
}

You might need to tweak it (with proper paths, the name of your Hyper-V network switch, etc.  But that’s the easy part.

Next time, I’ll add the logic to inject an unattend.xml to automate OOBE, name the computer, and join the AD domain…