VMware Cloud Community
roycesj
Contributor
Contributor

Syntax for multiple DNS servers and Suffixes?

Does anyone know the correct syntax for having multiple DNS servers and search suffixes in the New-OSCustomizationSpec command? Here is what I'm trying:

$VMspec = New-OSCustomizationSpec -FullName "$VMFullName" -OrgName "$VMOrgName" -OSType "Windows" -ChangeSid -Type Persistent -Name "$VMName-spec" -DnsServer "$VMDNS" -DnsSuffix "$VMSuffix" -NamingScheme "Fixed" -NamingPrefix "$VMName" -Workgroup "$Workgroup" -TimeZone "$TimeZone" -ProductKey "$WinLicense" -LicenseMode "$LicenseMode" -LicenseMaxConnections "$LicenseConns" -AdminPassword "$AdminPW"

Where "VMDNS = "10.1.1.1 10.2.2.2" and $VMSuffix = "suffix.org suffix.net" (both space separated). When I use this, the VM gets set to use DHCP rather than my configured static address (shows this in guestcust.log). However, if I change this to be "VMDNS = "10.1.1.1" and $VMSuffix = "suffix.org", then the whole network configuration gets set correctly. I suspect the problem gets causd by the invalid DNS server entry, since the customization wizard (if I edit the customization) actually shows the suffixes. Both on one line, so they don't work, but it does get set at least.

I can't find any documentation about the format these should have. Interestingly, these space-separated entries work just fine on my linux VMs.

0 Kudos
6 Replies
LucD
Leadership
Leadership

Both parameters accept an array of strings.

That means the format should be comma-separated strings.

$DNSServer = "10.1.1.1","10.2.2.2"
$$VMSuffix = "suffix.org","suffix.net"
$VMspec = New-OSCustomizationSpec -FullName "$VMFullName" -OrgName "$VMOrgName" -OSType "Windows" -ChangeSid -Type Persistent -Name "$VMName-spec" -DnsServer "$VMDNS" -DnsSuffix "$VMSuffix" -NamingScheme "Fixed" -NamingPrefix "$VMName" -Workgroup "$Workgroup" -TimeZone "$TimeZone" -ProductKey "$WinLicense" -LicenseMode "$LicenseMode" -LicenseMaxConnections "$LicenseConns" -AdminPassword "$AdminPW"

Does that work ?


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

roycesj
Contributor
Contributor

No. It actually still works for my Linux template, but the Windows template still goes back to DHCP when I use that syntax. So the comma-separated strings and the space-separated single string both work on Linux, but on Windows they both cause the VM to go to DHCP. Changing the entries to just use one DNS server works.

0 Kudos
LucD
Leadership
Leadership

Did you already have a look at fault.NicSettingsMismatch.summary? ?

I know it's not directly related but perhaps it could be something similar.

Look at Dimitar's answer and check the other thread he refers to.

I'll do some further testing as well.


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

0 Kudos
roycesj
Contributor
Contributor

Yes - in fact, I'm the one who submitted the original question. I don't think that is my problem - I'm not getting that mismatch error any more. In fact, I really don't see any errors at all. In the guestcust.log, it just says it is setting the NIC up to use DHCP, which isn't what I've set in the customization. Weird that if I change to use one DNS server and one DNS Suffix, then it works correctly. Changing either of these to use two (either space separated: '$DNS="10.1.1.1 10.2.2.2"' or two strings: '$DNS="10.1.1.1","10.2.2.2"') entries, and the customization reverts to use DHCP. On Linux, these both work correctly, which is even weirder (although in a way it makes sense, since the space-separated syntax is what is used in /etc/resolv.conf anyway).

0 Kudos
roycesj
Contributor
Contributor

OK, I found a work-around. It appears that I have to do this two different ways for Linux and Windows. As I said before, for Linux I can use either $VMDNS = "10.1.1.1 10.2.2.2" (space separated) or $VMDNS = "10.1.1.1","10.2.2.2" (comma-separated). Then this command works:

$VMspec = New-OSCustomizationSpec -OSType "Linux" -Type Persistent -Name "$VMName-spec" -DnsServer "$VMDNS" -DnsSuffix "$VMSuffix" -NamingScheme "Fixed" -NamingPrefix "$VMName" -Domain "$VMDomain"

However, when I use similar syntax for windows templates, it always sets the network card to use DHCP -- apparently because it doesn't like the format of the DNS server entries. The workaround I found was to do this a little differently:

$VMDNS1 = "10.1.1.1"

$VMDNS2 = "10.2.2.2"

Get-OSCustomizationNicMapping -Spec $VMspec | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress "$VMIPaddr" -SubnetMask "$VMMask" -DefaultGateway "$VMGateway" -Dns "$VMDNS1","$VMDNS2"

Note the difference: using the two variables and assigning them to the parameter in-line works correctly. Same for DNS Suffix. For some reason assigning the array variable beforehand doesn't work, but making this change seems to make the difference. I don't think this is related to the different commands (where DNS on Linux is set in the CustomizationSpec and Windows is set in the NicMapping), but the way the template handles the input from the command.

Anyway, this is working for me.

Thanks to VMware support who didn't get me the answer, but at least pointed me at this direction.

0 Kudos
m_f_irvin
Contributor
Contributor

I needed to have a solution that worked off of a CSV file to build multiple VMs with potentially different DNS servers.

I made this bit of code to go inside the "foreach" loop to parse the DNS field and build the $DNSSrvs string to accommodate different IPs depending on the value is the CSV file.

*** Note that the IPs must be space " " delimited in the CSV field.

*** the $VMc variable comes from the "foreach ($VMc in $VMs)" in my script.

############

$DNSSrvs = $Null  #reset value

$DNSSrvs = foreach ($DNSIP in $VMc.DNS.Split(" "))  #split DNS IPs

{

$DNSIP

}

#############

I tested this code with 1,2 and 3 IPs in the DNS field.

0 Kudos