VMware Cloud Community
BaconPhat
Contributor
Contributor
Jump to solution

PowerCLI: VAMI DNS Change

I've been fighting with it for 3 days, sucking up my pride needed to happen 2 days ago 😉

I am trying to update the VAMI DNS, using PowerCLI.  I get get the detail:

$DNSService = Get-CisService -Name "com.vmware.appliance.networking.dns.servers"
($DNSService.get()).servers
1.1.1.3
1.1.0.3
 
I can add:
$DNSService.Add("8.8.8.8")
($DNSService.get()).servers
1.1.1.3
1.1.0.3
8.8.8.8
 
How do I purge the existing content or simply replace the list?  I'm still learning the API content, I hope this is simple.
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Use the set() method, this overwites with what is in mode and servers (which is an array)

$DNSService.set(@{mode = 'is_static';servers = @('8.8.8.8')})

Make sure to first check with the get() method what the mode is set to. 


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

View solution in original post

Reply
0 Kudos
19 Replies
LucD
Leadership
Leadership
Jump to solution

Use the set() method, this overwites with what is in mode and servers (which is an array)

$DNSService.set(@{mode = 'is_static';servers = @('8.8.8.8')})

Make sure to first check with the get() method what the mode is set to. 


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

Reply
0 Kudos
BaconPhat
Contributor
Contributor
Jump to solution

Perfect!  I was wondering all over looking at how to set the various array details, that was indeed more simple than I was making it.  Thanks!

Tags (1)
Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Hi Lucd,

i have tried your Solution with VCSA 8. But it not works..

see here:

$dns = Get-CisService -Name 'com.vmware.appliance.networking.dns.servers'

$dnsservers = "1.1.1.1, 8.8.8.8"

When i put the variable in the servers String or the String itself is the same result:

$dns.set(@{mode = 'is_static';servers = @($dnsservers)})

$dns.set(@{mode = 'is_static';servers = @('1.1.1.1, 8.8.8.8')})

A server error occurred: 'com.vmware.vapi.std.errors.error': DNS Server: 1.1.1.1, 8.8.8.8 does not appear to be a valid IPv4 or IPv6 address. (Server error
id: 'com.vmware.applmgmt.err_invalid_dns_servers'). Check $Error[0].Exception.ServerError for more details.
At line:1 char:1
+ $dns.set(@{mode = 'is_static';servers = @('1.1.1.1, 8.8.8.8')})
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], CisServerException
+ FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Types.V1.CisServerException

Any Suggestions what i am doing wrong??

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik it should be an array of strings, not a single string

$dns.set(@{mode = 'is_static';servers = @('1.1.1.1', '8.8.8.8')})


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

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

When i try these i receive an other Error:

A server error occurred: 'com.vmware.vapi.std.errors.error': Operation Failed. (Server error id: 'com.vmware.applmgmt.err_operation_failed'). Check
$Error[0].Exception.ServerError for more details.
At line:1 char:1
+ $dns.set(@{mode = 'is_static';servers = @('1.1.1.1', '8.8.8.8')})
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], CisServerException
+ FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Types.V1.CisServerException

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you also do the get()?
What is the mode?


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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

When I do it this way it works for me.

$DNSService = Get-CisService -Name "com.vmware.appliance.networking.dns.servers"
$config = $DNSService.Help.set.config.Create()
$config.mode = 'is_static'
$config.servers = '1.1.1.1','8.8.8.8'
$DNSService.set($config)

$DNSService.get().servers


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

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Yes i have done these with a Custom Object:

$dnsCustom = [PSCustomObject]@{
Servers = ($dns.get().servers -replace '{}', '') -join ','
Mode = $dns.get().mode
}

Output:

Servers                              Mode
-------                                  ----
3.3.3.3,.4.4.4.4                is_static

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Strange... i have try these but i receive the same error back:

A server error occurred: 'com.vmware.vapi.std.errors.error': Operation Failed. (Server error id: 'com.vmware.applmgmt.err_operation_failed'). Check
$Error[0].Exception.ServerError for more details.
At line:1 char:1
+ $DNSService.set($config)
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], CisServerException
+ FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Types.V1.CisServerException

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you stop/start your PS/PowerCLI session, reconnect to the CisServer and run the code again.

I had similar issues in the past, a restart and reconnect helped.


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

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

I have restarted the CI Session and also restarted the vCenter itself.

Same Results 😞

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

On a vCenter with Version: 7.0.3 Build: 20150588 it works, but not on vCenter 8.0.0 Build: 20920323

 

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

When I look at the underlying REST API there seems to be a difference in the Body of the method.

V7 vs V8

Can you check what the following shows on V8 (I don't have a V8 available yet)?

$DNSService.Help.set | Get-Member

  


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

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

You´re right the Body has changed.

Output is:

$DNSService.Help.set | Get-Member


TypeName: System.Management.Automation.PSCustomObject

Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
config NoteProperty System.Management.Automation.PSCustomObject config=@{Documentation=DNS server configuration.; mode=; servers=}
Definition NoteProperty string Definition=void set(com.vmware.appliance.networking.dns.servers.DNS_server_config config)
Documentation NoteProperty string Documentation=Set the DNS server configuration. If you set the mode argument to "DHCP", a DHCP refresh is forced.
Errors NoteProperty Dictionary[string,string] Errors=System.Collections.Generic.Dictionary`2[System.String,System.String]
Returns NoteProperty string Returns=

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you use that snippet I posted earlier, with the 

$DNSService.Help.set.config.Create()

That should provide the correct layout of the config object.
Check with

$DNSService.Help.set.config.Create() | Get-Member


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

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Yes i have used that before

$DNSService.Help.set.config.Create()


mode servers                          
---- -------                          
     <Unset, Required, [List<string>]>
$DNSService.Help.set.config.Create() | Get-Member


   TypeName: System.Management.Automation.PSCustomObject

Name                       MemberType   Definition                                             
----                       ----------   ----------                                             
GetIUserInputValueInstance CodeMethod   PSObject GetIUserInputValueInstance()                  
ToString                   CodeMethod   PSObject ToString()                                    
Equals                     Method       bool Equals(System.Object obj)                         
GetHashCode                Method       int GetHashCode()                                      
GetType                    Method       type GetType()                                         
mode                       NoteProperty object mode=null                                       
servers                    NoteProperty ListTypeValue servers=<Unset, Required, [List<string>]>
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That should normally return an object with the correct layout for V8 version.
If it doesn't then there is an issue somewhere.
You could call the V8 Rest API directly, but you will have to authenticate first.


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

Reply
0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Ok Thx, but i have no Tools installed on that JS for API Connections directly like Postman...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can use the Invoke-WebRequest or Invoke-RestMethod cmdlets.


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

Reply
0 Kudos