VMware Cloud Community
adamjg
Hot Shot
Hot Shot
Jump to solution

Issue with New-OSCustomizationSpec when deploying a new VM

Hi all, I'm having an issue trying to deploy a VM from a script.  I started with LucD's code from this thread: https://communities.vmware.com/message/2220479#2220479. I'll start with the basic code I'm using:

$myCluster = Get-Cluster -Name "Cluster1" | Get-ResourcePool "Test"

$myTemplate = Get-Template -Name "Win 2008 R2 SP1 Std - Powershell"

$myDatastoreCluster = Get-DatastoreCluster -Name "DataStoreCluster1"

$myVM = "Adam12"

$IP = "10.0.0.1"

$SubnetMask = "255.255.255.0"

$Gateway = "10.0.0.254"

$DNS = "10.0.0.10","10.0.0.11"

Get-OSCustomizationSpec -Name "Server 2008 R2 Standard - Powershell" | New-OSCustomizationSpec -Name temp -Type NonPersistent

Get-OSCustomizationSpec -Name temp | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress $IP -SubnetMask $SubnetMask -DefaultGateway $Gateway -Dns $DNS

New-VM -Name $myVM -Location "Folder1" -Template $myTemplate -Datastore $myDatastoreCluster -ResourcePool $myCluster -OSCustomizationSpec temp

Very straight forward.  Now, I can use the New-VM command above directly against the template and OSCustomizationSpec and that works just fine (and of course manually provisioning works as well).  However, as soon as I try to make a new one and use the "temp" spec, the VM never gets to the rename process and I eventually get an oobe error stating "Windows could not parse or process unattend answer file".  I notice in the summary tab in vSphere that the IP address is correct based on the above, but the server name never changes from the original template name.

I stripped it down and took out line 10 above (setting the static IP) and just left it at DHCP and it failed the same way.  Any ideas as to what could be causing this?  Everything else works, it puts the VM in the right folder, the right datastore cluster and the right cluster.

As a bonus question: based on everything I've read, the VM Storage Profiles are not accessible via PowerCLI.  Has this changed at all?  It would be nice to set the profile in a script instead of having to go in and manually do it after the fact.  Thanks!

Adam

Reply
0 Kudos
1 Solution

Accepted Solutions
adamjg
Hot Shot
Hot Shot
Jump to solution

Answering my own post here...

Seems that this works if I create the New-OsCustomizationSpec with -Type Persistent instead of NonPersistent.  I'm on vSphere 5.0 and ESXi 5.0 with PowerCLI 5.1, so my guess is that those of you who are getting this to work are on vSphere 5.1.

I'm just starting my big upgrade to 5.5, so I'll re-visit this at that time.  For now I'm just going to create an 8 character random variable for the temporary custspec and delete it after the VM deploys.  Seems to work fine and I can have multiple people building VMs from various locations without stepping on each other.

View solution in original post

Reply
0 Kudos
1 Reply
adamjg
Hot Shot
Hot Shot
Jump to solution

Answering my own post here...

Seems that this works if I create the New-OsCustomizationSpec with -Type Persistent instead of NonPersistent.  I'm on vSphere 5.0 and ESXi 5.0 with PowerCLI 5.1, so my guess is that those of you who are getting this to work are on vSphere 5.1.

I'm just starting my big upgrade to 5.5, so I'll re-visit this at that time.  For now I'm just going to create an 8 character random variable for the temporary custspec and delete it after the VM deploys.  Seems to work fine and I can have multiple people building VMs from various locations without stepping on each other.

Reply
0 Kudos