I am using a script to deploy a VM with OS Customizations. It all works splendidly except for one thing: the VM name doesn't match the assigned hostname in the OS. The VM name could be "Test" and the hostname will be "Test-0". It always seems to append a "-0" (dash zero) on the end of the name of the VM for the hostname in Linux (haven't tried Windows to know if I have the same results).
Here is the line I use for the customization:
$VMspec = New-OSCustomizationSpec -OSType "Linux" -Type Persistent -Name "$VMName-spec" -DnsServer "$VMDNS" -DnsSuffix "$VMSuffix" -NamingScheme Vm -Domain "$VMDomain"
If I read this correctly, the "-NamingScheme Vm" should set the hostname to the same as the VM. It should use the VM name, and append a number only if there is another VM of the same name, but there isn't -- it doesn't matter what the VM name is (I've tried some pretty bizarre ones), they always add the -0 to the hostname in the guest Linux OS.
Has anyone seen this before? Any ideas what I'm missing?
Found an answer - one I'm not thrilled with, but one that does work.
It appears that the "-NamingScheme Vm" always appends a dash ( - ) followed by a digit (0, or whatever) to the hostname in the VM. I haven't gone through the wizard to see if that makes a difference, but I suspect it will work the same way. I worked around this by substituting "-NamingScheme "Fixed" -NamingPrefix "$VMName" " where $VMName was what I was using to name the VM anyway. There probably isn't a drawback to doing this in this way, except that I think the intent is less clear.