Automation

 View Only
  • 1.  Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 03:31 PM


    I'm looking for help to do the following: I have hundreds of VM servers, Windows 2003, WIndows 2008 and Windows 2012. Most of these VM are built and pickup a DHCP address which is then "reserved". I do have subnets for clustering and monitoring where the server's IP condiguration is set statically.

    I need to....

    1. Idenitify all VM servers that are statically configured. Output to a file

    2. Use the output to change the Primary and Secondary WINS servers

    Thanks in advance.......



  • 2.  RE: Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 05:32 PM

    You didn't say if all those VMs have the VMware Tools installed.

    And the current PowerCLI build doesn't support Windows 2012 for the Get-VMGuestNetworkInterface cmdlet.

    An alternative is to use WMI, provided these are all Windows OS VMs.

    Something like this

    &{Get-VM | %{
     
    Get-WmiObject -ComputerName $_.Name `
     
    -Query "select DNSHostName,IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE" |
     
    Select DnsHostName,@{N="IP";E={$_.IPAddress -join ','}}
    }}
    | Export-Csv static-ip.csv -NoTypeInformation -UseCulture

    Does that work for your VMS ?

    If yes, we can use the same WMI interface to change the DNS setting.

    Alan has an example in Change DNS and WINS on multiple servers



  • 3.  RE: Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 05:39 PM

    Yes, all VMs have VMWare Tools installed. These are all Windows Server VMs. I'm looking to change the WINS Primary and Secondary servers on all server VMs that are statically configured.  thanks



  • 4.  RE: Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 05:41 PM

    If you can reach them with WMI (did you try the script ?), then you also reconfigure them with WMI.



  • 5.  RE: Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 06:05 PM

    Yes, the script works, I have a test platform with no statically configured servers. Ran the script and the CSV was empty. Statically configured one of the servers, ran the script again and the server was in the CSV



  • 6.  RE: Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 06:07 PM

    Then you can combine that script with Alan's script to change the DNS servers.

    That should do the trick.

    Let me know if you need further help with that ?



  • 7.  RE: Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 06:14 PM

    Just one question, how does Alan's script pull the server names from the CSV using your script?

    function Set-DNSWINS {

    #Get NICS via WMI

    $NICs = Get-WmiObject ‘

    -Class Win32_NetworkAdapterConfiguration ‘

    -ComputerName $_ ‘

    -Filter “IPEnabled=TRUE”

    foreach($NIC in $NICs) {

    $DNSServers = “12.34.5.67″,”76.54.3.21″

    $NIC.SetDNSServerSearchOrder($DNSServers)

    $NIC.SetDynamicDNSRegistration(“TRUE”)

    $NIC.SetWINSServer(“12.34.5.67″, “76.54.3.21″)

    }

    }

    function Get-FileName {

    $computer = Read-Host “Filename of computer names?”

    return $computer

    }

    $f = Get-FileName

    Get-Content $f foreach {Set-DNSWINS}



  • 8.  RE: Change VM Server TCPIP Setting (WINS)
    Best Answer

    Posted Jan 08, 2014 07:20 PM

    Try like this

    $wins1 = "1.1.1.1"
    $wins2 = "2.2.2.2"

    Get-VM | %{
     
    Get-WmiObject -ComputerName $_.Name `
     
    -Query "select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and DHCPEnabled=FALSE" | %{
       
    $_.SetWINSServer($wins1,$wins2)
      }
    }


  • 9.  RE: Change VM Server TCPIP Setting (WINS)

    Posted Jan 08, 2014 07:36 PM

    This script does both, if I connect to a vCenter server and run the script it changes the WINS servers for only the servers with a static IP address. This is perfect, thank you