The Lowercase w
9May/140

vSphere Performance: The story behind my new book

I’m very happy to announce that my new book called VMware vSphere Performance, along with co-authors Rynardt Spies and Christopher Kusek, has been released! It’s available right now on Kindle format and the hard copy will be available on May 12th!

bookcover

The book is focused on providing guidance for how to design vSphere to get the best performance out of your virtual machines.  I wanted the book to be more than a paperback version of vSphere’s own performance best practices paper – we’ve also included tips, tricks, and stories of what we’ve seen in the field with real customers.  We also include some tips for troubleshooting performance problems that you may encounter.  We hope you’ll find it valuable across current and future versions of vSphere.

Background Story

I first became involved with this book back in late 2011 as the book’s technical editor.  There were numerous delays and issues that aren’t worth getting into, but there was very little progress.  I had been emailing back and forth with one of the authors of the book, Jonathon Fitch, trying to help where I could and give guidance whenever possible.  It was during those email exchanges that he told me he was fighting cancer.

Fast forward to early 2013, and I’m in the middle of writing Virtualizing Microsoft Business Critical Applications on VMware vSphereI had been emailing with Jonathon to see if he was making any progress when he told me that his disease had progressed to a point where he didn’t think he’d be able to finish the book.  He tried to get into some experimental treatment program but unfortunately he didn’t quality, and his doctors told him he had just a few weeks left.  The news hit me pretty hard even though I didn’t know him well.

I told Jonathon I would take over his chapters, making sure as much of his content remained in the book as possible, and that his name would remain on the cover. (Sybex originally agreed to that but changed their minds and his name is not printed on the cover – I'm not happy about it but I understand their decision)  After not hearing from him for a little while and thinking the worst, I got the bad news that on April 1, 2013, Jonathon had died.  His wife told me that he was very proud of being a part of the book and it was important to him.

I didn’t know Jonathon before becoming involved in this book and mostly communicated with him through email.  He wasn’t active on Twitter or other social media so he wasn’t well known.  Even still, he was a member of our virtualization community and it’s sad to lose one of our own.  I tried to keep as much of his original content in the book so that his hard work would survive. We dedicate this book to Jonathon and I sincerely hope that his family is proud of what he was able to accomplish while fighting his disease.

It was a long road to finishing this book – I was still writing the VBCA book and was also involved in Mastering VMware vSphere 5.5, so the idea of taking on another book was not high on my list but I made a commitment to Jonathon so I stuck with it.  It wasn’t without it’s challenges to say the least.  I wanted to keep as much of his content in the book as possible, but his chapters were still largely based on the content he’d written in 2011, some of it going as far back as vSphere 4.1.  What do you do when you don’t fully understand what he meant in a sentence or paragraph and you can’t ask him to clarify? Or how do you keep the original author’s words intact when he’s writing based on a version of vSphere that’s 3 revisions older than the current version?

Much of the time I felt like Dante from Clerks when he would say, “I’m not even supposed to be here today!”  If you’re familiar with Clerks then you’ll know what I mean.  Or, see below.

Thankfully I was able to push through the issues and challenges and produce something I think Jonathon would be proud of.  I did what I could to keep his words intact while updating the content to be relevant to the most recent version of vSphere.  I wish we could have kept his name on the cover, but his hard work paid off and we have all dedicated the book to him.  I really hope it brings his family some comfort.

Rather than end on a sad note, instead I’d rather post some pictures of my adorable kids holding a copy of the book.  :)

2014-05-08 12.41.43  2014-05-08 12.41.13

9Apr/146

One Weird Trick to Virtualize Monster VMs–Consultants Hate This!

We’ve all seen those ads on the Internet that promise to teach us “one weird trick” that “<someone> hates” to do something easily.  Make money fast?  Yep.  Lose belly fat?  Check.  Grow “other” parts of your body?  Easy.

Oneweirdtrick  everyonehateshim

I couldn’t resist stealing the headline for something that I’ve seen come up time and time again when virtualizing large applications or monster VMs.

Raise your virtual hand if you’ve heard, or said, something like this in the past:

All VMs should start out with only 1 vCPU.

Most VMs don’t need more than 1 vCPU.

Giving a VM more than 1 vCPU could hurt performance.

I hear this one all the time.  I even used to say something like it myself.  When I think back to my early days with virtualization I used to say things like, “If a server needs more than 3.6GB of RAM, it probably isn’t a good candidate for virtualization.” (3.6GB was the max RAM supported in a guest OS in ESX 2.x)  But is that the right way to approach sizing all virtual machines?

These days, most of the time I hear something like this as a result of a software vendor’s sizing guidance for their application.

“Why should I give that VM 4 vCPUs and 16GB of RAM? There is no way it really needs it!”

The thing to remember here is this: While starting small when sizing VMs is a good practice, the application’s actual requirements should dictate the sizing.  That’s the “one weird trick” – understand the application’s requirements before rushing to judge the sizing.  Just because you don’t like the idea of giving a VM a lot of resources doesn’t mean it doesn’t actually need them.  Trust me – I’m a big believer in starting small and sizing VMs with fewer resources if the resource requirements are not well known or defined.  That doesn’t apply to all VMs.

I hear it too often – folks who automatically rush to judge the sizing of a virtual machine just because they think it’s “too big.”  We need to get past the mentality of “anything larger than 1 vCPU is bad.”

I’m going to put this ad on other virtualization blogs!

Before you head to the comments and say something like, “Vendor supplied requirements are BS.  Vendor x told me that their application needed y requirements and it doesn’t use even half of that.” hear me out.  Is that true sometimes?  Definitely.  But should that be your default answer?  Definitely not.  If the application you’re trying to virtualize is currently physical, a good way to determine if the sizing is accurate is to simply measure the existing load.  But don’t forget – the current utilization alone is not enough to size the VM.  You need the application’s actual requirements.  I’ll illustrate that point with a story.

I worked with a customer last year to help them virtualize an important Microsoft SharePoint FAST Search implementation.  We ran capacity assessments on the existing physical servers with both VMware Capacity Planner and Microsoft Assessment and Planning Toolkit.  Both tools independently came to the same conclusion: based on the current utilization, these servers likely need 2 vCPUs and 8GB of RAM.

When I worked with the FAST architects, they wanted their servers sized with 8 vCPUs and 24GB of RAM.  Naturally there was confusion as to why the current physical servers were only using a quarter of those resources.  It came down to one thing: requirements.

The customer had a specific requirement to be able to support a certain number of QPS (queries per second) at a certain level of latency.  In order to meet those requirements we needed to size the servers with 8 vCPUs and 24GB of RAM.  We validated that design by running FAST performance tests at different CPU/memory sizing on the FAST VMs.  Each time we were not able to meet the QPS requirements unless it was sized correctly.

What’s the moral of this story?  Don’t be afraid of giving a virtual machine the resources it actually requires.  Remember – there are tools like vCenter Operations that can tell you, over time, how a VM is using its resources.  This provides you the opportunity to right-size the workload if the VM truly doesn’t need the resources.

Understand the vendor stated requirements as well as those of your customer/application owner.  If you get a request for a SQL Server (or similar) and your immediate response is, “I’m not giving it that many vCPUs…” stop and make sure you truly understand the application’s requirements.  Validate the sizing with performance testing and adjust if necessary.  You’ll have happier application owners and better performing applications.

18Mar/140

Perception is Reality When Virtualizing Business Critical Apps

It’s been too long since I’ve blogged anything on a regular basis.  Sorry about that.  I would love to blame it on the three books I’ve written in the last year but that isn’t the only reason.  Hopefully I can turn it around and start writing on a regular basis again.

I’ve been sitting on this one for a while but finally had some time to get it down.  When it comes to virtualizing business critical applications, the perception of poor performance from virtualized application becomes reality whether it is true or not.  It might be because organizations tried to virtualize performance intensive applications years ago when the ESX/ESXi platform was less mature and that memory lingers.  It’s up to us to help educate those organizations that VMware has improved vSphere considerably and it is now capable of scaling to meet the demands of just about any application.

Fighting perception often means fighting nonsensical things that vendors say.  Before I get into this I wanted to say that I consider Microsoft to be very virtualization friendly.  They provide excellent guidance for virtualizing many of their products.  Unfortunately not all of their guidance is so great.

Take a look at the following guidance on virtualizing FAST Search Server (component of SharePoint 2010) – bold emphasis is mine:

FAST Search Server 2010 for SharePoint supports virtualization, but for larger deployments, we recommend that you only use virtualization for your test and development environments- not the production environment. Our rationale is as follows:

  • FAST Search Server 2010 for SharePoint is a heavy user of CPU and IO

  • Virtual machines only have access to a limited number of CPU cores (Hyper-V = 4, VM ware = 8)

  • Virtual machines will give 30-40% decrease in overall performance

Yes – it’s bad enough that I’m actually ignoring that they spelled VMware as “VM ware” and focusing on the fact that they say virtual machines will give a 30-40% decrease in overall performance.  I’m not sure where they’re getting this data (perhaps on older versions of vSphere or Hyper-V) but it isn’t true today.  Having been personally involved in the performance tests of production FAST Search Server deployments I can say definitively that that is not the case as long as it’s sized corrected (like any other app).

My advice to you: If you see a vendor make a claim like this, ask for the data to back it up.  Perform your own testing and validate whether it’s true.  Make them prove it.

If we all fight this perception maybe vendors will notice and finally stop saying things like this.  We all benefit when that happens.

4Nov/133

Virtualizing Exchange and Scaling Up

I have to admit - Exchange virtualization is one of my favorite topics.  I love talking about it with customers, colleagues, or anyone who will listen. It has a very well known workload profile which makes sizing consistent, it’s virtualization friendly in that it supports vSphere features like vMotion and HA, and I like talking about the challenges and creative solutions that are sometimes required to virtualize it. Yep, Exchange virtualization is my pal.

I’m also very familiar with its support limitations as I’ve written about them in the past (see here). One of the support policies has to do with CPU over-subscription. That is, assigning more vCPUs than there are physical pCPUs in the host. From Microsoft’s support policy page for Exchange 2013 virtualization (though this applies to Exchange 2010 also):

Many hardware virtualization products allow you to specify the number of virtual processors that should be allocated to each guest virtual machine. The virtual processors located in the guest virtual machine share a fixed number of logical processors in the physical system. Exchange supports a virtual processor-to-logical processor ratio no greater than 2:1, although we recommend a ratio of 1:1. For example, a dual processor system using quad core processors contains a total of 8 logical processors in the host system. On a system with this configuration, don't allocate more than a total of 16 virtual processors to all guest virtual machines combined.

Note the section I bolded above – that says that you cannot go beyond a 2:1 vCPU to pCPU ratio and 1:1 is recommended. Not only are we used to much larger consolidation ratios, once you factor in DRS automatically moving VMs to balance out utilization it becomes almost impossible to enforce.

Combine this with the relative disparity between the maximum amount of RAM in a host compared to CPUs. We have customers that have deployed ESXi hosts that have 16-24 physical CPUs but 1TB of RAM. If you want to virtualize Exchange on those servers, you’re left with only two possible outcomes:

1) You ignore Microsoft’s support restriction and exceed the 2:1 vCPU/pCPU ratio.

2) You don’t use anywhere near the amount of RAM you have in the host.

The good news is there’s a third option that allows you to work around this problem: CPU reservations. CPU reservations in vSphere allow you to guarantee that important virtual machines will have access to the CPU resources they need even if CPU resources are constrained. This works great for virtualizing Exchange for a few reasons:

1) You can effectively exceed the 2:1 vCPU:pCPU ratio for workloads other than Exchange while guaranteeing Exchange VMs access to those CPU resources. Doing so does not violate Microsoft’s support policies – see this great TechEd presentation on virtualizing Exchange where Microsoft’s Jeff Mealiffe discusses this as an option.

2) Hosts that have a disproportionate amount of RAM to CPUs can still be utilized without wasting resources.

The other nice thing about CPU reservations is that when resources are not over-subscribed, CPU resources can be shared evenly with VMs that do not have a CPU reservation. In this way they work differently than memory reservations, which do not allow reserved memory resources to be shared with other VMs even if memory is plentiful. With CPU reservations, when resources are available then all VMs get equal access to the CPU. Once CPU resources become over-subscribed, the VMs with a reservation get guaranteed access to their reserved CPU resources while VMs without CPU reservations do not.

It’s worth mentioning that this post came about mostly as a result of a Twitter conversation that Chris Wahl (@ChrisWahl) brought me into recently. This is one of the reasons why I love Twitter – great conversation that led to sharing of information.

I hope this helps those that are looking to virtualize Exchange and are concerned about the CPU over-subscription limitations. Using CPU reservations in vSphere will let you stay compliant with Exchange support while allowing you to over-subscribe CPU resources for non-Exchange workloads.  Everybody wins!

1Nov/131

Where Have I Been?

Looking at this blog over the past 12 months kind of makes me sick.  If you ignore posts that have to do with books and a guest blog post by my brother, you’ll see I’ve only published maybe two or three posts all year.  That’s very bad, though the explanation for why can be found in those posts.

I’ve made it very obvious that I wrote a book about virtualizing business critical applications. I’ve been less outgoing about the fact that I’ve actually been involved in three book projects. Yep – three books in one year.  In addition to the VBCA book, there’s also Mastering VMware vSphere 5.5 and another called VMware vSphere Performance that will be out next year (I’ll write a blog post on the Performance book as that’s a bit of a unique situation).  I’m planning on writing a blog post that talks about writing a technology book in general but suffice to say the effort that goes into writing along with the fact that I have a young family (4 year old and a 1 year old) I’ve had very little time. 

The third book is nearly complete and that should free up a lot of my time. I have a task list with several blog topics to write about and more in my head so I’m hoping to once again fill this site with useful virtualization information.

To those who still visit the site and still have me in your RSS feeds – thanks for sticking with me.  Hopefully over the coming weeks you’ll see a lot more from me.

Tagged as: 1 Comment
17Oct/130

Great deal on Kindle edition of Virtualizing MS Business Critical Apps

Amazon has the Kindle edition of Virtualizing Microsoft Business Critical Applications on VMware vSphere at a great price. It's currently only $22.99, compared to $38 for the paperback version.

You can grab the Kindle edition here: http://www.amazon.com/Virtualizing-Microsoft-Applications-Technology-ebook/dp/B00E8HSWQU/

I'm a little late in announcing this so hopefully the price stays at this level for a little while.  If you already have the paperback and want the Kindle edition for on the go reading, now is a great time to pick up a copy.

To those that have already purchased the book - thanks so much for your support and we hope you enjoy!

27Aug/130

New book announced: Mastering VMware vSphere 5.5

Now that VMware has officially announced vSphere 5.5, we’re very happy to announce that the new version of the best selling Mastering vSphere series will be released as well!  Mastering VMware vSphere 5.5 will be out a little bit later this year and brings with it all that you need to know about the new version of vSphere.

Nick Marshall deserves a ton of credit here for taking the reigns on this book and helping to drive it.  He did a ton of work to keep up with all of the beta releases and incorporate all of the new features into the product.  He did a great job a deserves a lot of credit.  Scott Lowe, a veteran of this book series, was excellent as usual.

I was thrilled to be involved in this project and think you’ll really enjoy the new version this year.  Along with me was Forbes Guthrie of vReference fame.  Forbes has contributed to this book in previous versions and is also the author of two editions of the great book vSphere Design. We also had Josh Atwell, automation master, adding his awesome content as well.

There’s lots of new features and capabilities in vSphere 5.5 and we’re confident that this book will help you understand everything you need to know.  Looking forward to the release!

image

21Aug/130

VMware Press “Meet the Author” Event at VMworld

Interested in getting your copy of a VMware Press book signed by the author(s) while at VMworld this year?  VMware Press will be holding a Meet the Author event at VMworld to give you the opportunity to do just that!

Come to the bookstore at VMworld on Wednesday, August 28th from 12:30-1:30 for a chance to meet the authors, chat about anything you want, and get your book signed.  I’ll be there, along with co-author Alex Fontana, signing our new book and other VMware Press authors will be there too.  We really hope to see you there.

No need to sign up or anything – just show up and say hi!

Tagged as: , No Comments
14Aug/130

Release of Virtualizing MSFT Business Critical Apps book!

After months of late nights and hard work, I’m very happy to announce that the book Virtualizing Microsoft Business Critical Applications on VMware vSphere, co-authored with Alex Fontana of VMware, has been released!  The official release date from VMware Press was August 7th, and it will be officially in stock at Amazon on August 16th.  It can be ordered from Amazon here http://www.amazon.com/Virtualizing-Microsoft-Business-Applications-Technology/dp/0321912039/ or directly from VMware Press here http://www.pearsonitcertification.com/store/virtualizing-microsoft-business-critical-applications-9780321912039. Both paperback and Kindle/eBook copies are available.

We were also very honored to get none other than Mark Achtemichuk to write the Foreward for our book.  Mark is a Senior Technical Marketing Architect at VMware, a performance guru, VCDX, and all around awesome guy.  Mark has been a performance junkie for many years and has seen time and again that you can be successful virtualizing business critical applications with proper planning and design.  We’re thrilled to have someone of his caliber endorse our book.

Both Alex and I (as well as several other VMware Press authors) will be at a book signing at VMworld on Wednesday, August 28th from 12:30PM-1:30PM. We hope to see you there!

Both of my kids loved their copies!

2013-08-12 17.04.032013-08-12 18.55.36

Both Alex and I hope you enjoy the book and don’t hesitate to reach out with any questions or comments.  And don’t be shy about leaving your reviews on Amazon as well!

image

11Jul/133

Deploying a VM with PowerCLI in a Semi-Complex Environment

The following is a guest blog post by my brother Ben Liebowitz.  I guess virtualization runs in the family!  Follow him on Twitter at @ben_liebowitz.

------------------------------------------------------------------------

Last year, while working at a previous employer, I wanted to make it easier for less-experienced team members to deploy VMs, while making sure little to no mistakes are made.  I decided to go down the path of a PowerCLI script.

Before I get into the script that I wrote, I feel I should describe the environment.  A simple way for inexperienced co-workers to deploy VMs without them going on the wrong network/datastore, etc.

      • vCenter 4.1
      • Combination of ESX/ESXi 4.1
      • VM Platforms:
        • Development
        • Staging
        • Production
        • Workstations
      • Datastores:
        • vol_cdrives_dev
        • vol_cdrives_stg
        • vol_cdrives_prd
        • vol_transient_dev (for temp & swap files)
          (although the volume name is transient, the VMDKs don't get removed after time)
        • vol_transient_stg (for temp & swap files)
          (although the volume name is transient, the VMDKs don't get removed after time)
        • vol_transient_prd (for temp & swap files)
          (although the volume name is transient, the VMDKs don't get removed after time)
        • vol_datadrives_dev
        • vol_datadrives_stg
        • vol_datadrives_prd
        • vol_workstations
      • Networks
        • DEV_STAGING
        • PROD
      • Folders
        • DEV
          • various sub-folders
        • STAGING
          • various sub-folders
        • PRODUCTION
          • various sub-folders

My templates only had a C drive, so the transient VMDK needed to be created (and data VMDK if necessary, not all VMs received data partitions).  The template VMs all lived on a templates datastore to keep space free on the production datastores.  As you can imagine, after deploying the VM from template, there were several steps that had to be done, manually.  I wanted to simplify that so other members of my team, or other teams, could deploy VMs without needing assistance from senior members of the team.

The script was written by taking examples of scripts that I found online and modifying them to fit my needs.

Here is a step by step breakdown of the script:
(you can click on each image for a larger version)

1. Run the script.
image

2.  The script connects to vCenter.
image

3.  A list of OS’s is displayed. Select a number from 1 to 11.
image

4. Once you selected a template, the choice you picked is displayed for 3 seconds.
(Along with this choice, a customization that goes with that OS is put into a variable.)
image

5.  Then you’re prompted to select a platform.
image

6.  You’re then shown what you choose, again, for 3 seconds.
(Along with this choice, a cdrives datastore, transient datastore, parent folder and network are fed into variables)
image

7.  You’re then shown a list of folders for the platform you selected in step 5.  If you just hit enter, the VM is placed at the root of the platform’s folder.
image

8.  The folder you selected (along with the platform’s folder) is displayed for 3 seconds.
image

9.  Then, you’re prompted to enter the name of the VM.
image

10.  The VM Deployment then begins.  You’ll now see a task show up in vCenter for the VM Deployment.
image

The VM is then deployed, just as it would from the VI Client.  After it’s done, the script changes the network, the folder location, and adds the transient VMDK.  Finally a message is displayed reminding them, after powering the VM on, to wait for it to restart and sysprep to run.  I always set my customizations to auto-login once, this way, I know it’s done when it’s logged in.

11. After the VM is deployed, the network portgroup is changed.
image

12. Then the folder location is changed to the choice you selected above.
image

13. And finally, the Transient VMDK is created and added.
image

The last steps were to assign an IP and change the drive letters.  C was always OS, D was always Transient, and E was always Data.  I wrote a separate script to change the CD drive letter to G, mount the new transient volume, and format/assign it’s drive letter.

When done, here’s a screenshot of the VM in vCenter.
image

 

Here is the script:
-----------------------------------------------------------------------------

write-host "VM Deployment Script"
write-host "Created by Ben Liebowitz"
write-host "version 1.0 - 8/27/2012 - BLiebowitz"

# Connect to vCenter
write-host "Connecting to vCenter..."
write-host "If Credentials are needed, you will be prompted."
connect-viserver -server vc.lab.local

# Template & Customization Selection
write-host "Select which template to deploy from:"
write-host ""
write-host "1. Windows 2008 R2 Standard Edition x64"
write-host "2. Windows 2008 R2 Enterprise Edition x64"
write-host "3. Windows 2008 R1 Standard Edition x86"
write-host "4. Windows 2008 R1 Enterprise Edition x86"
write-host "5. Windows 2008 R1 Enterprise Edition x64"
write-host "6. Windows 2003 R2 Standard Edition x86"
write-host "7. Windows 2003 R2 Standard Edition x64"
write-host "8. Windows 2003 R2 Enterprise Edition x86"
write-host "9. Windows 2003 R2 Enterprise Edition x64"
write-host "10. Windows 2000"
write-host "11. Windows XP"

$SIndex = read-host "Select a Template. Enter a number ( 1 - 11 )"

if ($SIndex -eq 1) {
$OS = "Windows 2008 R2 Standard Edition x64"
$TEMP = get-template -name "win2008r2std"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2008 (R2)"
} elseif ($SIndex -eq 2) {
$OS = "Windows 2008 R2 Enterprise Edition x64"
$TEMP = get-template -name "w2k8r2ent64"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2008 (R2)"
} elseif ($SIndex -eq 3) {
$OS = "Windows 2008 R1 Standard Edition x86"
$TEMP = get-template -name "w2k8r1std32sp1"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2008 (R1)"
} elseif ($SIndex -eq 4) {
$OS = "Windows 2008 R1 Enterprise Edition x86"
$TEMP = get-template -name "w2k8r1ent32sp1"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2008 (R1)"
} elseif ($SIndex -eq 5) {
$OS = "Windows 2008 R1 Enterprise Edition x64"
$TEMP = get-template -name "w2k8r1ent64sp1"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2008 (R1)"
} elseif ($SIndex -eq 6) {
$OS = "Windows 2003 R2 Standard Edition x86"
$TEMP = get-template -name "w2k3r2std32sp2"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2003 R2 x86 Standard Edition"
} elseif ($SIndex -eq 7) {
$OS = "Windows 2003 R2 Standard Edition x64"
$TEMP = get-template -name "w2k3r2std64sp2"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2003 R2 x64 Standard Edition"
} elseif ($SIndex -eq 8) {
$OS = "Windows 2003 R2 Enterprise Edition x86"
$TEMP = get-template -name "w2k3r2ent32sp2"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2003 R2 x86 Enterprise Edition"
} elseif ($SIndex -eq 9) {
$OS = "Windows 2003 R2 Enterprise Edition x64"
$TEMP = get-template -name "w2k3r2ent64sp2"
$CUSTOM = get-oscustomizationspec -Name "Windows Server 2003 R2 x64 Enterprise Edition"
} elseif ($SIndex -eq 10) {
$OS = "Windows 2000"
$TEMP = get-template -name "WIN2000"
$CUSTOM = ""
} else {
$OS = "Windows XP"
$TEMP = get-template -name "WINXP"
$CUSTOM = Get-oscustomizationspec -Name "Windows XP Professional"
}
write-host ""
write-host "You Picked: "$OS
write-host ""
start-sleep -s 3

# DEV/STG/PROD
write-host "Select Dev, Staging, Production or Workstation."
write-host ""
write-host "1. DEV"
write-host "2. STAGING"
write-host "3. PRODUCTION"
write-host "4. WORKSTATION"
$cdrive = read-host "Enter a number ( 1 - 4 )"
if ($cdrive -eq 1) {
$DATASTORE = "vol_vm_cdrives_dev"
$TRANSIENT = "vol_vm_transient_dev"
$TFOLDER = "Development"
$NETWORK = "Dev_Staging"
} elseif ($cdrive -eq 2) {
$DATASTORE = "vol_vm_cdrives_stg"
$TRANSIENT = "vol_vm_transient_stg"
$TFOLDER = "Staging"
$NETWORK = "Dev_Staging"
} elseif ($cdrive -eq 3) {
$DATASTORE = "vol_cdrives_prd"
$TRANSIENT = "vol_transient_prd"
$TFOLDER = "Production"
$NETWORK = "PROD"
} else {
$DATASTORE = "vol_vm_workstations"
$TFOLDER = "Workstations"
$NETWORK = "Prod_view"
}
write-host ""
write-host "You Picked: "$TFOLDER
write-host ""
start-sleep -s 3

# Folder Selection
write-host "Select which folder to store the VM..."
$FOLDER = get-folder -location $TFOLDER | Select Name | Sort-Object Name
$i = 1
$FOLDER | %{write-host $i":" $_.Name; $i++}
$SIndex = read-host "Select a Folder. Enter a number ( 1 -" $FOLDER.Count ")"
$SFOLDER = $FOLDER[$SIndex - 1].Name
write-host ""
write-host "You Picked folder: "$TFOLDER" "$SFOLDER
write-host ""
start-sleep -s 3

# VM Name Selection
$NAME = read-host "Please Enter the VM's Name: "

write-host ""
write-host "You Entered: "$NAME
write-host ""
start-sleep -s 3

# DEPLOYMENT VM
# *** You must use an ESX/ESXi host with the new-vm command, not your vCenter server.
new-vM -VMHost host1.lab.local -Name $NAME -Template $TEMP -Datastore $DATASTORE -OSCustomizationSpec $CUSTOM

# Change Network
# *** the Virtual Switch name may need to be changed to reflect the vswitch in your Environment
write-host "Changing the Network Portgroup..."
write-host ""
$VirtualPortGroup = get-vmhost host1.lab.local | get-virtualswitch -Name vSwitch0 | get-virtualportgroup -name $NETWORK

Get-VM -Name $NAME | get-networkadapter | set-networkadapter -NetworkName $VirtualportGroup -Confirm:$False

# Change Location
write-host "Moving the VM to the folder you selected above."
write-host ""
Move-VM -VM $NAME -Destination (Get-Folder -Name $SFOLDER -Location $TFOLDER) -confirm:$false

# Add Transient Hard Disk
write-host "Adding Transient Hard Disk."
write-host ""
new-harddisk -VM $NAME -CapacityKB 8388608 -StorageFormat Thin -datastore $TRANSIENT

write-host "After powering the VM on, wait for it to restart and sysprep to run."
write-host "After rebooting, the VM will auto-login once."
write-host "Then mount/format the D (Transient) drive, assign IP and join domain"

-----------------------------------------------------------------------------

As I mentioned, here is the script I wrote to change the CD drive letter and mount the D drive.  (the FORMAT command in DISKPART doesn’t work with some versions of Windows, so YMMV.)

-----------------------------------------------------------------------------

# Powershell script to change CD Drive Letter from D to G
# Created by BLiebowitz on 28-AUG-2012

(gwmi Win32_cdromdrive).drive | %{$a = mountvol $_ /l;mountvol $_ /d;$a = $a.Trim();mountvol G: $a}

# Get-WmiObject -Class Win32_LogicalDisk -ComputerName $NAME -Filter "DriveType=5" |foreach-Object {$_.DeviceID}

{
$DiskNum = 1
$DiskLBL = "Local Disk"

$command = $Null
$command = @"
SELECT DISK $DiskNum
ATTRIBUTES DISK CLEAR READONLY
ONLINE DISK
CONVERT MBR
CREATE PARTITION PRIMARY ALIGN=64
ASSIGN LETTER=D
FORMAT FS=NTFS UNIT=64k LABEL=$DiskLBL QUICK
"@
$command | diskpart
}

-----------------------------------------------------------------------------

Enjoy!

Go to top ↑