So last time we looked and saw a way to create a standardized workstation for deployment on SCVMM 2008.   Of course I say “Workstation” when it really could even be a server, a web server, an additional file server for DFS.  It could be anything.

But now we’re going to see the REAL power of SCVMM 2008.   Powershell commandlets.

As with all the current Microsoft technology, the GUI is really just a system that’s building a Powershell script and running that script.   That’s it.   And initially when you look at the SCVMM 2008 script for deployment your reaction will be the same as mine.

“Where do I start with this thing?”

In actual fact there is only ONE line you need to worry about if you’re deploying, the rest are building variables and content for that one line.    They all do need to be there for that line to work, but you don’t actually need to fiddle with them.

The important line is right at the bottom of the generated script


The line you see that starts with “NEW-VM” is what you’re interested in from that script.  That’s it!  And use of that script (Just do quick “SAVE AS” in Notepad and give it a name, say NEWWorkstation.PS1) and you’re off to the races.

So in the self generated script I have this in my final line

New-VM -Template $Template -Name"Workstation01" -Description "" -VMHost $VMHost -Path "C:VirtualMachines" -JobGroup 972411ef-4233-4e96-8e52-b95e472dd7fd -RunAsynchronously -Owner "TECHDAYSAdministrator" -HardwareProfile $HardwareProfile -ComputerName "*" -FullName "Techdays" -OrgName "Techdays" -TimeZone 35  -AnswerFile $null -OperatingSystem $OperatingSystem -RunAsSystem -StartAction AlwaysAutoTurnOnVM -DelayStart 0 -StopAction SaveVM


For the uninitiated, pick your eyeballs off the ground, sit down.  It’s not scary.  It’s WORDY but not scary.  There’s only really three spots you need to be concerned with.

The section marked “-Name”, “–Description” and “-Computername”

Now you could manually edit these fields each time to get what you wanted, but well to be honest, that kills the luster of Powershell.  The computer should work for YOU.

So here’s a very simple approach.   Use a “READ-HOST” and have it prompt you for the needed information.  And really, what changes from one standard workstation to the next?  The name and possible description.

So at the very top of the script or even just before the “NEW-VM” line place these commands

$ComputerName=READ-HOST ‘Key in name of Workstation’
$Description=READ-HOST ‘Type in the Description’

And then change where it says -Name “Workstation01 , -Description “” and –Computername “*” to read

-Name $Computername, –Description $Description and –Computername $Computername

So the line now reads as

New-VM -Template $Template –Name $Computername -Description $Description -VMHost $VMHost -Path "C:VirtualMachines" -JobGroup 972411ef-4233-4e96-8e52-b95e472dd7fd -RunAsynchronously -Owner "TECHDAYSAdministrator" -HardwareProfile $HardwareProfile -ComputerName $Computername -FullName "Techdays" -OrgName "Techdays" -TimeZone 35  -AnswerFile $null -OperatingSystem $OperatingSystem -RunAsSystem -StartAction AlwaysAutoTurnOnVM -DelayStart 0 -StopAction SaveVM

Of course some parts of this line will reflect your particular configuration, but those THREE are the ones you need to change to have this self generated script be repeatable to your needs.

Next time we’ll take a look at using this same script to deploy multiple machines at the same time with a very minor change.


Script on!
The Energized Tech