Script to modify network settings, server name, and domain. RRS feed

  • Question

  • Hello all!

    Often, I have to change the network settings on a mass quantity of servers, which takes a while to do manually. I am wondering if there was a way to use a .csv file as reference and use the serial number as the identifier for the server's network settings in the .csv file? These are HP DL380e G8 servers mostly, so to get the serial in the powershell, you have to use the WMIC command to get serialnumber.

    So to reiterate here is the flow I would like to be able to use:

    Start script> Script pulls the servers serial number> Script uses serial number pulled to match the serial number bank in the .csv file > Script then uses configuration settings to the right of that serial number (Network, domain, and server name)

    Is something like this possible? Even just network settings would help a ton. Another idea I have had is to use a small vb program to generate the .csv file based on information given. Any help would be greatly appreciated!

    • Moved by Bill_Stewart Friday, October 24, 2014 1:49 AM This is not "scripts on demand"
    Sunday, July 20, 2014 7:09 AM

All replies

  • $Path = "C:\Computers.csv"
    $File = Import-CSV -Path $Path

    ForEach ($Line in $File)
    {  $SerialNumber = $Line.SerialNumber
       $ComputerName = $Line.ComputerName
       $Domain = $Domain
       $Bios = get-wmiobject -class win32_bios -ComputerName $ComputerName
     | Select SerialNumber
       If $SerialNumber -eq $Bios.SerialNumber
          do something


    Sunday, July 20, 2014 7:30 AM
  • Thank you! From what I can tell, it appears to change the domain and computer name. How would I add network configuration to this script?
    Sunday, July 20, 2014 8:15 AM
  • It does not change anything, it assumes the cvs file contains serialnumber, computername, domain.

    for each computername in the csv file, it pulls the serialnumber from that computer and checks that the serialnumber matches with what's in the csv file.

    To gather some network configuration, other classes could be similarly called like win32_networkadapter for example, but a more comprehensive report would be netsh with an export option.

    It is possible to configure the networks settings from csv file using powershell cmdlets (similar to above) and/or netsh but that is risky. Would want to test it in a lab environment like on virtual machines on a private network. Some examples can be found here:

    Windows Server 2012 R2 Test Lab Guide


    Sunday, July 20, 2014 8:59 AM
  • Thank you! I am planning on testing on one of our test servers as well as a VM of 2012 SP0 R2.
    Sunday, July 20, 2014 9:44 AM
  • The script is logically incorrect.  What you are asking does not make any sense.

    It sounds like you are asking for someone to write a script for you. This forum is not for free scripts.  YOU must write your own script.  We will answer questions and help you learn how to write a script.

    Here are some things to think about

    #1 What does a serial number have to do with network settings?

    #2 How can you find a server that does not have a network configured using WMI?

    You either need to rethink your question or explain why you think you need to do this.


    Sunday, July 20, 2014 1:03 PM
  • Not quite. In fact, I just am used to C# and Ruby, but for some reason the powershell scripting objects and the way in which you use them hasn't quite clicked for me yet. I am a very visual learner, so I can make sense out of how to do it. I am not asking for someone to do it for me, but a frame or nudge in the right direction would be amazing considering I am pretty much a noob. Also, I am stuck to using powershell in the environment in which I need to perform this kind of work. 

    So, let me explain the serial number thing to you... Essentially, I am starting from scratch on said property's servers, right? I have information in which I typically organize my VLAN info (IP, gateway, and the like) in a spreadsheet. The way I can keep track of these is not by the hostname (Servers have a fresh image and a generic name is used) but by other physical HP identifiers like the serial number or asset tag. So, if I can write a script that uses the serial number of the server to pull information correlating to that serial number in a csv spreadsheet, I can automate a lot of this process. It's not off the wall for me to have to do 50+ servers in a day, which takes me away from other high priority work. So if I can speed this up, it would help a ton.

    I don't know the answer to the second question. I just started researching automating network configuration via powershell earlier today.

    Thanks in advance

    Sunday, July 20, 2014 3:35 PM
  • Also, I have a csv file created if someone is curious as to all the information that would need to be set. 
    Sunday, July 20, 2014 3:46 PM
  • How are you going to query a server that doe s not have a network configured.  You are jumping into the technical middle of the issue.  We have no idea how your servers are attached to your network.  If they are on a domain it is easy. If they are not on a network then what you are asking is missing information.

    Are you trying to run a script during installation of the server to configure the network?  If so you are asking the wrong question in the wrong forum as this is a common deployment issue.  If you are asking how you can change network settings on a domain server then you may have other issues since remotely changing network settings on a networked server is much harder. If you are on a network but not in a domain then the issue is even different.

    So you see most of your question problems are due to a lack of knowledge of the technology.  Programming in a C languaue has nothing to do with networks or domain technologies.

    In most systems today we establish VLANs via DHCP permanent reservations.  These are allocated by MAC address.  Once allocated they are virtually permanent physical addresses. We can set the scope to reflect all global settings for each VLAN.

    If you just want to set the VLAN ID then all of the above are still important to defining a solution.

    The days ot the spreadsheet IP database were over many years ago.  Your problem here is one reason why this has happened.

    The above example of how to match a computer to an IP is one way to do it.  The better method is to update the spreadsheet with the computer name then use the spreadsheet to either allocate DHCP reservations or to set the network cards.

    Warning. Doing this in a batch operation can and likely will disable and destabilize the whole network.  Plan carefully and test completely.


    Sunday, July 20, 2014 4:42 PM