Automation

 View Only
Expand all | Collapse all

PowerCLI: VAMI DNS Change

  • 1.  PowerCLI: VAMI DNS Change

    Posted Apr 26, 2022 08:13 PM

    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.


  • 2.  RE: PowerCLI: VAMI DNS Change
    Best Answer

    Posted Apr 26, 2022 08:32 PM

    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. 



  • 3.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 26, 2022 08:42 PM

    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!



  • 4.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 08:59 AM

    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??



  • 5.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 09:02 AM

    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')})


  • 6.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 09:18 AM

    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



  • 7.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 09:25 AM

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



  • 8.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 09:36 AM

    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



  • 9.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 09:36 AM

    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
    


  • 10.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 09:47 AM

    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



  • 11.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 09:49 AM

    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.



  • 12.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 10:05 AM

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

    Same Results



  • 13.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 10:17 AM

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

     

     



  • 14.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 10:30 AM

    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

      



  • 15.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 10:43 AM

    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=

     



  • 16.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 10:58 AM

    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


  • 17.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 11:04 AM

    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>]>


  • 18.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 11:07 AM

    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.



  • 19.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 12:48 PM

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



  • 20.  RE: PowerCLI: VAMI DNS Change

    Posted Apr 06, 2023 01:05 PM

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