VMware Cloud Community
rlboyd
Contributor
Contributor
Jump to solution

Confusing help for Set-VMhostNetwork -DNSaddress and -SearchDomain

I wanted to create a script to verify/update various DNS and NTP settings for my entire collection of VMhosts across several datacenters and clusters.  So I was experimenting with Get-VMHostNetwork and Set-VMHostNetwork. 

I was frustrated with the rather terse help text for these cmdlets.   The help for the Set-VMHostNetwork cmdlet specifies that the values for -DNSaddress and for -SearchDomain should be strings.   The help text fails to mention what form the parameter should be if providing multiple values.  Based on my experiments If it's given as an inline text string it can be given as a comma separated list.   However, if providing the same as a $variable, the variable must be of type array with one value per element.   It would be extremely helpful if this is spelled out in the help text and in the examples. 


Is my interpretation correct? I'm using PowerCLI 5.1

0 Kudos
1 Solution

Accepted Solutions
ssbkang
Enthusiast
Enthusiast
Jump to solution

When you take a closer look at the help:

Set-VMHostNetwork [-Network] <VMHostNetworkInfo[]> [-ConsoleGateway <String>] [-VMKernelGateway <String>] [-VMKernelGatewayDevice <String>] [-ConsoleGatewayDevice <String>] [-DomainName <String>] [-HostName <String>] [-DnsFromDhcp [<Boolean>]] [-DnsDhcpDevice <Object>] [-DnsAddress <String[]>] [-SearchDomain    

    <String[]>] [-IPv6Enabled [<Boolean>]] [-ConsoleV6Gateway <String>] [-ConsoleV6GatewayDevice <String>] [-VMKernelV6Gateway <String>] [-VMKernelV6GatewayDevice <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

It mentions <String[]> which means, it could be a single string or an array with multiple strings.

For example:

Get-VMHostNetwork -VMHost (Get-VMHost -Name "Your ESXi") | Set-VMHostNetwork -DnsAddress "10.10.1.1" -SearchDomain "test.com"

This will set DNS address to 10.10.1.1 with custom suffix to be test.com.

Get-VMHostNetwork -VMHost (Get-VMHost -Name "Your ESXi") | Set-VMHostNetwork -DnsAddress @("10.10.1.1","10.10.1.2") -SearchDomain @("test.com","test.test.com")

This will set DNS address to 10.10.1.1 and 10.10.1.2 with custom suffix to be both test.com and test.test.com

Not sure I understood correctly but hope this helps.

Steven.

View solution in original post

0 Kudos
3 Replies
ssbkang
Enthusiast
Enthusiast
Jump to solution

When you take a closer look at the help:

Set-VMHostNetwork [-Network] <VMHostNetworkInfo[]> [-ConsoleGateway <String>] [-VMKernelGateway <String>] [-VMKernelGatewayDevice <String>] [-ConsoleGatewayDevice <String>] [-DomainName <String>] [-HostName <String>] [-DnsFromDhcp [<Boolean>]] [-DnsDhcpDevice <Object>] [-DnsAddress <String[]>] [-SearchDomain    

    <String[]>] [-IPv6Enabled [<Boolean>]] [-ConsoleV6Gateway <String>] [-ConsoleV6GatewayDevice <String>] [-VMKernelV6Gateway <String>] [-VMKernelV6GatewayDevice <String>] [-WhatIf] [-Confirm] [<CommonParameters>]

It mentions <String[]> which means, it could be a single string or an array with multiple strings.

For example:

Get-VMHostNetwork -VMHost (Get-VMHost -Name "Your ESXi") | Set-VMHostNetwork -DnsAddress "10.10.1.1" -SearchDomain "test.com"

This will set DNS address to 10.10.1.1 with custom suffix to be test.com.

Get-VMHostNetwork -VMHost (Get-VMHost -Name "Your ESXi") | Set-VMHostNetwork -DnsAddress @("10.10.1.1","10.10.1.2") -SearchDomain @("test.com","test.test.com")

This will set DNS address to 10.10.1.1 and 10.10.1.2 with custom suffix to be both test.com and test.test.com

Not sure I understood correctly but hope this helps.

Steven.

0 Kudos
rlboyd
Contributor
Contributor
Jump to solution

Apparently this works too:


Get-VMHostNetwork -VMHost (Get-VMHost -Name "Your ESXi") | Set-VMHostNetwork -DnsAddress 10.10.1.1,10.20.2.2 -SearchDomain test.com,other.com


and based on your point, this must mean that in this context stringa,stringb is treated as an array of strings, not as a simple string.  If one puts quotes around the list of values it's rejected as an invalid parameter.  I appreciate you pointing out this fine detail about the syntax of the cmdlet.   I find the notation for it to be a bit obtuse -- not quite as easily obvious as BNF or other forms.   The [] is too much like the optional parameter designation [ Parameter ] to easily set it apart in my eye.

0 Kudos
vjosuz
Enthusiast
Enthusiast
Jump to solution

What if I want to update the secondary DNS address, without updating Primary one? Any way to do that? I just dont want VC to have another update task when updating primary DNS is not required.

0 Kudos