PowerCLI Script to change the DNS servers and domain name

Hello

Brand new to PowerCLI, I'm trying to create a script that will change the domain name and the DNS servers of my ESXi servers. I found that I need to update the Vmware.Vim.HostDnsConfig to update these settings. I created the following script and the following error.

$config = new-Object VMware.Vim.HostDnsConfig
$config.domainName = "new.domain.com".
$config.address = new-Object System.String [] (2)
$config.address [0] = "10.69.69.80".
$config.address [1] = "10.69.70.80".

_this $ = get-view-Id "HostNetworkSystem-networkSystem.

_this $. UpdateDnsConfig ($config)

You can not call a method on a null value expression.

Line: 1 char: 23

+ $_C. UpdateDnsConfig < < < < ($config)

+ CategoryInfo: InvalidOperation: (UpdateDnsConfig:String)], RuntimeException

+ FullyQualifiedErrorId: InvokeMethodOnNull

I guessed the error message that I need to a value in the host name, I do not need to change the host name. So I create a variable to remove the host name and place it in the $config. Line received host name but still a mistake because the variable is pulling more information that I need.

$hostname = get-VMHost | Select name

$config. Hostname = $hostname

When I insert the above code I have an error.

Exception by calling 'UpdateDnsConfig' with '1' or the arguments: ' year error occurred during the configuration of the host.
Line: 1 char: 23
+ $_C. UpdateDnsConfig < < < < ($config)
+ CategoryInfo: NotSpecified: (:)) [], MethodInvocationException)
+ FullyQualifiedErrorId: DotNetMethodException

When I look at the $config I see the following.

DHCP: false
VirtualNicDevice:
HostName: @{Name = ESXI01}
Domain name: new.domain.com
Address: {10.69.69.80, 10.69.70.80}
SearchDomain:
DynamicType:
DynamicProperty:

Of course the @{Name = ESXI01} will not work. Someone can explain how to get a host name in a variable and pass it to the Config.Hostname?

You should be able to do easily by using the command "set-vmhostnetwork.

I don't think that you can just write to VMWare.Vim.HostDnsConfig.

Tags: VMware

Similar Questions

  • PowerShell script to change the DNS entries for all hosts

    Ive tried many others which have been posted on the web and none work... Someone at - it a script to change the DNS entries on all hosts?

    OK, changed a few pieces my end, it worked but now it's... Try this (50% confident

     $dnsServers = ("192.168.111.3","192.168.111.4")
    
     Get-VMHost | Get-View | %{
        $ns = Get-View -Id $_.configManager.networkSystem
        $dns = $ns.networkConfig.dnsConfig
    
         $dns.Address = @()
         foreach($server in $dnsServers) {
           $dns.Address += $server
       }
       $ns.UpdateDnsConfig($dns)
     }
    

    If you found this information useful, please consider the allocation of points for correct or helpful.

    Alan Renouf

    http://Virtu-al.NET

  • PowerCli Script to change the VM Options?

    Is it possible to use PowerCli to change the options for a virtual computer?  Specifically, I would like a PowerCli script to select control of boxes on a virtual machine under Options-> VMware Tools-> advanced settings until the VMware Tools are upgraded during the feeding cycle and the time is sync would be.

    Thank you

    JD

    Here's what we use if you want to pull from a text file.

    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
    #$vmConfigSpec.Tools.ToolsUpgradePolicy = "manual"
    $vmConfigSpec.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
    
    Get-Content -Path "C:\names.txt" | %{
        (get-vm -Name $_).Extensiondata.ReconfigVM($vmConfigSpec)
    }
    
  • My hotmail account has certainly was hacked and used to change the DNS settings on a vauable domain name registration.

    My hotmail account has certainly was hacked and used to change the DNS settings on a vauable domain name registration. Indeed, they stole the domain name, which used my hotmail account as account checking the change of domain name registration. It is a police matter. How can I get the security of Hotmail team to freeze the mail in the account and then return the account for me? I am the owner of long-standing account, since 1995. What should I do to prove that I am the rightful owner of the account?

    How can I contact Hotmail security ASAP?

    Hi JoePiecora,

    Thanks for posting your question in the Microsoft answers Forum. For any question on Hotmail, please visit the following link:

    http://windowslivehelp.com/forums.aspx?ProductID=1

  • Im trying to open the tutorial of 23 minutes on how to use different tools in photoshop and it continues to come with unable to resolve the DNS servers worked fine yesterday? Ive had creative cloud on my laptop for a week and still have not been able t

    Im trying to open the tutorial of 23 minutes on how to use different tools in photoshop and it continues to come with unable to resolve the DNS servers worked fine yesterday? Ive had creative cloud on my laptop for a week and not yet able to get past the basics make me very frustrated.

    I guess you meant the links when you open photoshop CC. I tested all four videos of the 23 min tutorial and they all played fine. If something between you and adobe does not work correctly.

    • Check that your firewall is blocking the net. Try to access youtube videos and see if they play very well
    • Go to the adobe tv site and try to play one of the videos here. Adobe TV
    • If youtube plays very well and adobe tv does not work, next is to check if you have flash installed. Some videos require flash, others are html 5. Sorry that I could not confirm what player has been used for this tutorial. I think that html 5 but not sure.
    • Next is to look at the properties of your browser and check multimedia settings are not disabled if it y in a. (this is totally dependent on the browser)

    If none of this helps, let us know.

  • Script to change the subnet and vlan.

    Hello

    Please can anyone help with a script to change the subnet and VLANs on all the esx host in a cluster for the vmotion and management network interface?

    Thank you

    Astra

    I guess it worked because you pasted an out front, so:

    Get-Cluster mycluster. Get-VMHost | Get-VMHostNetworkAdapter | where {$_.} PortGroupName - eq "VMotion"} | {} %
    Game-VMHostNetworkAdapter - VirtualNic $_ - IP $_. IP - subnet mask "255.255.254.0" - confirm: $false
    }

    I guess that makes still out:

    Get-Cluster mycluster. Get-VMHost | Get-VMHostNetworkAdapter | where {$_.} PortGroupName - eq "VMotion"}

    2 vmknis right?

    If Yes, then it should work I think.

  • Script to change the name of the file to the virtual machine and its associated files

    Hello

    I'm looking for a script to change the name of the virtual machine in virtual center and also change it has associated file names in the data store to match file name of virtual machine. But the vmdk file will contain a descriptor which maps the - flat.vmdk file. So not sure that we can achieve this through a script.

    Thanks in advance!

    Not really as much as I know.

    The advantage of the svMotion is renamed it the files (.) VMX, VMDK,...) For you.

    The only alternative would be the command line. See Duncan Howto: renaming a virtual computer.

    With the help of the plink.exe tool which could possibly be scripted.

    ____________

    Blog: LucD notes

    Twitter: lucd22

  • can not change the dns server, always comes back.

    10.10.5 Yosemite

    My ISP has provided DNS servers are terrible and I still get messages "site is not reachable. I'd like to change the DNS from Google or Open DNS servers

    In SYSTEM preferences > network > DNS tab I delete 2 default entries & entry "8.8.8.8" & "8.8.4.4" (google dns)
    In the "areas of research" box, there are 2 entrances & I can't delete them.

    I click OK & apply - when I go back to the DNS tab, it was the old DNS.

    What should do?

    May be a corrupt .plist.

    Make a backup, preferably 2 backups on 2 separate drives.

    Quit the application.

    Go to Finder and select your user folder. With this Finder window as the windshield, select Finder/display/display options for presenting or order - J.  When the display options opens, check "show the library folder. This should make your visible user library folder in your user folder.  Select the library. Then go to Preferences/com.apple.systempreferences.plist.  Move the .plist on your desktop.

    Restart your computer, open the application and test. If it works fine, delete the plist for the office.

    If the application is the same, return the .plist where you got it, crushing the latest.

    Thanks to leonie for certain information contained in this.

  • Change the DNS settings in the Pool of IP network

    Hello

    Due to a migration of our DNS servers, I have to change the IP addresses of the DNS servers defined in the (currently used) our BDE server IP pools. There is a Hadoop cluster with a large amount of data running using this pool and I do not have to deploy the cluster again. Restart of the cluster is not matter, so I planned the settings DNS for the cluster nodes have to change after reboot. Unlikely, I could not change the DNS settings. Is there a way (perhaps non-elegant) change those settings for the pool?

    See you soon,.

    Dustin

    Hi Dustin,

    BDE provides the interface to change the DNS server in the network added to the BDE.  You must change the BDE database to do.  Here is the solution:

    1 Server BDE connect you as user serengeti

    2. run this command: echo ' network dns1 set update = 'the_new_dns_server_ip' where name = 'the_network_name '; \q" | psql

    3. apply the new DNS server. There are two approach. You can choose one.

    (a) connection BDE CLI and run "cluster stop - name...". ' and 'start cluster - name... '. "to restart the virtual machines in the cluster, then the new DNS server will be applied.

    (b) on BDE server, run "serengeti - ssh.sh cluster_name " sudo sed-i of | nameserver. * | nameserver the_new_dns_server_ip| ' g' / etc/etc/resolv.CONF. The new DNS server should take effect immediately.

    Thank you for using BDE.

    Jesse @BDE

  • Get-VMHost: you have changed the world: DefaultVIServer and global: DefaultVIServers system variables. This is not allowed. Please reset them to $null and reconnect the server vSphere.

    Hello world

    After the upgrade to PowerCLI version 5.1 however I can't run even the simplest command because it always ends up with the following error:

    Get-VMHost: you have changed the world: DefaultVIServer and global: DefaultVIServers system variables. This is not aRA. Please reset them to $null and reconnect the server vSphere.

    C:\Users\Albert\AppData\Local\Temp\7900df01-f6c1-48c6-ac1e-047dfff90fb6.ps1:1 tank: 11
    + Get-VMHost < < < <
    + CategoryInfo: NotSpecified: (:)) [Get-VMHost], InvalidState)
    + FullyQualifiedErrorId: VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidState, VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVMHost

    Can someone please suggest to me how to fix the script for my v3.2.0 PowerGUI IDE can work with the latest PowerCLI in my computer laptop 64 bit Windows 7?

    Thank you.

    And I just tried with PowerGui (same versions of PowerGUI and PowerCLI you use), no problem.

    Must be something local on your desktop.

    Maybe try a uninstall/reinstall of PowerGUI?

  • Changing the DNS server for ESX hosts?

    Our network administrator will change the IP address of the DNS server.  In this way, we will change those corresponding to ESX hosts.

    We would like to know

    (1) can we change the DNS server on execution of the ESX hosts without going into maintenance mode?

    (2) under what circumstances the ESX host will do use DNS servers?

    (3) memory, we should add all the IP addresses of ESX host in the hosts file in the Service Console, where is this hosts file located at?

    Thank you

    Tony,

    Use "service network restart" command to restart the network service

    Do not forget also that...

    Very dependent on DNS HA, HA will not work without the correct DNS configuration. The servers ESX and vCenter server must be able to resolve the name (FQDN full) / IPs in both feel to get a working HA.

  • How to manually change the DNS zone files?

    I'm running OS X version 10.11.2 (El Capitan) and using App Server version 5.0.15 on a Mac Mini.

    I need to change the DNS Zone files manually because the DNS Server App Manager does not provide a U / I in order to add some elements (such as adding a delegation, etc.).  I use TextWrangler (5.0.2) as editor-in-Chief.

    I found an old post on how to do this here, but the information listed it seems obsolete.

    I was able to find the zone files to:

    / Library/server/name

    as:

    CBI .

    When I try to save or overwrite the db. files, or try to save all the files in that directory, I get an error indicating that:

    "Save the authenticated for this file failed (error application code: 20004).

    Since a window Terminal, if I go to that directory and type:

    Echo hello > temp.txt

    I get:

    Permission denied

    I am logged in using an administrator account.

    Before editing the db. files, I turned off the DNS in the App Server, then exit the server application server.

    What should I do to manually update the db. files?

    These files are protected from root.  You need to elevate your permissions to be able to change them.

    Probably you use a text editor like vi, nano or pico command line.  sudo vi/path/to/file for example.

    Back up the files first to protect against error.  In addition, be aware that Apple can run on some of your changes if you change the.app areas.

    Reid

    Apple Consultants Network

    Author of "El Capitan Server" - Foundation Services: available exclusively in Apple iBooks Store

    Author of "El Capitan Server - Collaboration & control": available exclusively in Apple iBooks Store

    Author of books of Yosemite server and server Mavericks

  • my fonts disappeared! When I go to change the system fonts and fixedsys... What do I do?

    I use Vista Home Basic and a little more than a month I've had problems with the script!  All the lines and symbols... I have restored until I can't do a day earlier that when this problem happened!  Finally, I changed the standard windows fonts and I use somethings, but much is still in the symbols (dashes, lines, etc.).  I went into my fonts folder in Control Panel and my folder is empty!  When I go to change the system fonts and fixedsys... What do I do?

    Hi Vickie,

    If you see only the fonts system and no additional (specific program) installed fonts, then you can try the following steps and check.

    Most likely, the fonts are installed on your computer are hidden. Did the same by following these steps.

    Method 1:

    a. open fonts by clicking the Start button, clicking Control Panel, appearance and personalization, and then clicking fonts.

    b. now click organize , and then click on folder and search options.

    c. click the display and check to select Show hidden files, folders and drives.

    d. click apply and OK. Check if you see all the fonts.

    (Make sure that show you the files hidden after the repair is done by selecting don't show hidden files, folders and drives.)

    Method 2:

    Try to perform the clean boot procedure and check if it helps.
    How to troubleshoot a problem by performing a clean boot in Windows Vista or in Windows 7

    After the troubleshooting steps, please refer to clean the boot link to put the computer to normal startup mode.

    For more information, you can also read the following article.

    The problems of fonts

    You can also read the following article and check.

    Fonts: Frequently asked questions

    Hope this information is useful.

  • How to connect without changing the DNS on the Client Windows 7 computer to the 2008 R2 domain controller?

    I have a Windows Server 2008 R2 Enterprise domain controller configuration and some Windows 7 computers. I use this for a home network for safety because we rent a part of the property and still have guests. The part being rented has 2 portable Windows 7 Professional that guests can use.

    I want to connect all computers to the domain controller without changing the DNS settings on them. How to get to do and please put detailed instructions?

    This issue is beyond the scope of this site and must be placed on Technet or MSDN

    http://social.msdn.Microsoft.com/forums/en-us/home

  • script to change the data type of column

    Hi gurus of the oracle.

    I have 190 tables in my database.

    I have the column type CHAR of all these tables data.

    I need to change the data type of CHAR in VARCHAR2 for all these tables...

    There the script to change the data type of all tables at once?

    Please help me in this regard.

    Thanks in advance

    Concerning

    REDA

    Hello

    There is nothing built-in to Oracle SQL to do.  Maybe your front-end has certain characteristics.

    You can write dynamic SQL statements to do.  In other words, you can write a query that the output is a SQL script like this:

    ALTER TABLE TABLE_A CHANGE (A_TXT1 VARCHAR2 (5))

    A_TXT2 VARCHAR2 (10));

    ALTER TABLE TABLE_B CHANGE (B_TXT1 VARCHAR2 (5));

    with one row for each column of type CHAR.  Notice how the first line of output for each table begins with ALTER TABLE... but the later lines at the same table.  Similarly, the last line of a table (which will be the same as the first row, if the table has only one column of type CHAR) to end with a semicolon, but other lines are not.

    Here's a way to generate and execute such a dynamic script in SQL * more:

    -Disable the features that make the output easy to read, but hinder the execution
    SET FEEDBACK OFF
    SET LINESIZE 500
    SET PAGESIZE 0

    -Create fix_char.sql
    COIL c:\some_pathename\fix_char.sql

    SELECT THE CHECK BOX
    WHEN ROW_NUMBER () OVER (PARTITION BY table_name
    ORDER BY column_name
    )  = 1
    THEN 'ALTER TABLE ' | table-name
    || "CHANGE (").
    ELSE «»
    END
    ||        column_name
    ||        "VARCHAR2 (').
    ||        DATA_LENGTH
    ||        ')'
    ||        CASE
    WHEN ROW_NUMBER () OVER (PARTITION BY table_name
    ORDER BY column_name DESC
    )  = 1
    THEN '); "
    Output END AS
    Of user_tab_columns
    WHERE data_type = "CHAR".
    ORDER BY table_name
    column_name
    ;

    SPOOL OFF

    -Turn on the features that make the output easy to read, but hinder the execution
    SET FEEDBACK ON
    SET LINESIZE 80
    SET PAGESIZE 50

    -Fix_char.sql performance
    @c:\some_pathname\fix_char

    It's good to change all the CHARIOT of VARCHAR2 columns.  The CHAR data type is nothing trouble.

Maybe you are looking for

  • Error message: not available with this Apple ID update

    App Store displays the available updates, but after choosing "Update", the error message starts "Update not available with this Apple ID" appears. All of the applications in question were purchased with the current Apple ID. Mac Pro (2008), 10.11.4

  • delete 2d array in the while loop

    I have a table 2D being initialized outside of the loop executing a state machine, how would a clear table 2d in the while loop? I guess I'm not sure what to wire a constant matrix empty 2D too =)

  • Hard USB unplug

    Hey guys,. I bought V570 model 2 days and I was wondering if its normal I really have a hard time to remove any peripheral USB on it, as really having a hard time, I basically have to hold tight the laptop and force out usb (especially my external ha

  • I need more of a reboot

    I deleted everything in the MUSIC folder, PLAYLIST, even deleted all the photos, but when I turn on the unit, several playlists are there, and when I try to play a song, it freezes.  (Because the song is not on the device.) I rebooted (pushed on butt

  • BlackBerry Smartphones Blackberry is down of calls

    I have a torch 9810. Unlocked white. Recently my phone begins to call whenever I made a call or received a call. The service drops to SOS and the call is suddenly lost. The network is fine because the other ppl are able to call. I need help! The perp