VMware Cloud Community
wsaxon
Contributor
Contributor

Using New-VM and OSCustomizationSpec with 'custom' hostname

This may be recorded elsewhere but I have not found an answer yet.

I would like to deploy a new VM using a template and then apply a customization spec to it afterwards. I have a spec already set up, but it joins the Windows machine to a domain and also requires a 'custom' hostname. If I attempt to use it thusly:

Set-VM -VM $vm -OSCustomizationSpec $spec

Two problems occur:

  1. It asks for confirmation even though I did not specify the optional -Confirm. I don't want to confirm what I just asked for - is there a way to disable this?

  2. The command fails with "A specified parameter was not correct. hostname"

I've tried creating a specification $newspec and then using:

Set-OSCustomizationSpec -Spec $newspec -NewSpec $spec

to copy in the configuration of $spec, with the idea being to also set the NamingScheme and NamingPrefix, but this also fails unless $newspec is created with matching workgroup/domain configuration, which I don't want to do. The error I get here is "Domain or Workgroup are mutuall exclusive".

Am I just approaching this all wrong? It seems like a simple set of requests.

Reply
0 Kudos
3 Replies
halr9000
Commander
Commander

The answer to the first question is "-Confirm:$false".

--

Hal Rottenberg / hal@halr9000.com<mailto:hal@halr9000.com> / halr9000.com<http://halr9000.com>

Microsoft MVP (PowerShell) / VMware vExpert

Co-Host, PowerScripting Podcast / Director, PowerShellCommunity.org

"Managing VMware Infrastructure with PowerShell: TFM", now shipping!

Follow me on Twitter: http://twitter.com/halr9000

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
stromcooper
Contributor
Contributor

Glad to see Hal addressing your first question, but I have a similar issue with your part two. I am working on some script for VM deployment based on CSV data (have used many sources both here and blogosphere) and have it almost done. The final component I'm going for is VM IP'ing. I have found two approaches:

1) Use Invoke-Script and netsh on my Windows VMs to set IP / Subnet / DNS / WINS / DNS

2) Use Set-OSCustomizationNicMapping to apply the IP values to a customization spec

The first option seems to have an error when setting multiple VMs simultaneously. One VM will receive its IP info correctly and the others throw errors. The second option is rather appealing to me, however I do not want to edit my stored customization spec. Is there any way to create a new customization spec (NonPersistent), copy the properties from a permanent one saved within VC and then edit the NonPersistent copy's NicMapping to set IP values for the VM? It would seem straightforward enough, but I haven't been able to figure out how to do so yet.

Any advice would be appreciated. Thanks!

Reply
0 Kudos
LucD
Leadership
Leadership

Just a thought.

The SDK contains a DuplicateCustomizationSpec method, which allows you to copy an existing Customization Specification to a new one.

$mySPec = "Master spec"
$copySpec = "Temp spec"
$OScustMgr = Get-View CustomizationSpecManager
$OScustMgr.DuplicateCustomizationSpec($mySpec,$copySpec)

You can then use this new/copied Customization Specification as described in the Deploying a VM with Static IP in 3 Steps blog post to deploy your guest(s).

Once you're finished with the Customization Specification, you can safely throw it away with the help of the Remove-OSCustomizationSpec cmdlet.

Remove-OSCustomizationSpec -Name $copySpec -Confirm:$false

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos