Announcement

Collapse
No announcement yet.

How to create multiple (hundreds) IP address using powershell in single Server 2003 ?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create multiple (hundreds) IP address using powershell in single Server 2003 ?

    Hi All,

    I'd like to perform database application transactional and concurrent load testing which requires approx. 100 IP address in a single host (Windows Server 2003 box) so that one NIC can have multiple IP address.
    Is there any quick way (Powershell / NetSH) to create those IP address in one single box ?

    example:

    Code:
    VM-Simulator1 - 10.2.1.1
    
    10.2.1.2
    10.2.1.3
    10.2.1.4
    10.2.1.5
    .
    .
    .
    10.2.1.102
    Code:
    VM-Simulator2 - 10.2.2.1
    
    10.2.2.2
    10.2.2.3
    10.2.2.4
    10.2.2.5
    .
    .
    .
    10.2.2.102
    i know how to do it in Windows Server 2003 manually one by one but that's too daunting to do it manually.

    Thanks.
    Last edited by Albertwt; 9th April 2010, 03:24.

  • #2
    Re: How to create multiple (hundreds) IP address using powershell in single Server 20

    IIRC there is a registry key that holds the alternate IPs so you should be able to create multiple keys with PS
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: How to create multiple (hundreds) IP address using powershell in single Server 20

      Originally posted by Ossian View Post
      IIRC there is a registry key that holds the alternate IPs so you should be able to create multiple keys with PS
      Thanks for the reply Ossian, All i need is example to create the IP address, i just don't know where / how to start.

      Comment


      • #4
        Re: How to create multiple (hundreds) IP address using powershell in single Server 20

        http://www.petri.com/configure_tcp_i..._same_time.htm

        http://www.google.co.uk/search?hl=en...meta=&aq=f&oq=
        Tom Jones
        MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
        PhD, MSc, FIAP, MIITT
        IT Trainer / Consultant
        Ossian Ltd
        Scotland

        ** Remember to give credit where credit is due and leave reputation points where appropriate **

        Comment


        • #5
          Re: How to create multiple (hundreds) IP address using powershell in single Server 20

          This will probably work on the local host...
          If you want to use something like psexec you can modify it.

          Code:
          $I = 2
          do {
              $IP = "10.2.1." + $I
              netsh interface ipv4 add address  "Local Area Connection" $IP 255.255.255.0
              $I++
              }
          while ($I -le 102)
          Marcel
          Technical Consultant
          Netherlands
          http://www.phetios.com
          http://blog.nessus.nl

          MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
          "No matter how secure, there is always the human factor."

          "Enjoy life today, tomorrow may never come."
          "If you're going through hell, keep going. ~Winston Churchill"

          Comment


          • #6
            Re: How to create multiple (hundreds) IP address using powershell in single Server 20

            Originally posted by Dumber View Post
            This will probably work on the local host...
            If you want to use something like psexec you can modify it.
            Netsh -r connects to remote computer.

            Powershell's range operator is just what this problem needs. Bonus points for single-liner.
            Code:
            10..20 | % {iex ([string]::format("netsh interface ipv4 add address 10.10.10.{0} 255.255.255.0",$_))}
            -vP

            Comment


            • #7
              Re: How to create multiple (hundreds) IP address using powershell in single Server 20

              But harder to understand
              Marcel
              Technical Consultant
              Netherlands
              http://www.phetios.com
              http://blog.nessus.nl

              MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
              "No matter how secure, there is always the human factor."

              "Enjoy life today, tomorrow may never come."
              "If you're going through hell, keep going. ~Winston Churchill"

              Comment


              • #8
                Re: How to create multiple (hundreds) IP address using powershell in single Server 20

                Originally posted by Dumber View Post
                But harder to understand
                True dat. I just enjoy being a show-off with Powershellisms. Or that's what my colleaques say.

                Anyway, the PS oneliner can be deconstructed as:

                "10..20 |" - Create a range from ten to twenty and pipe it forward in the object pipeline.
                " % {" - for each item the range created and piped, do
                "iex " - invoke-expression, or, run
                "(" - evaluate the stuff in parenthesis before passing it to iex
                "[string]::format("netsh interface ipv4 add address 10.10.10.{0} 255.255.255.
                0",$_)) } " - Call .Net String Class static method Format(). This will create a string in which {0} is replaced with whatever is in the parameter list. In this case, the parameter list will contain current object in the | % pipeline, that is, a member of the range the first command created.

                -vP

                Comment


                • #9
                  Re: How to create multiple (hundreds) IP address using powershell in single Server 20

                  Originally posted by vonPryz View Post
                  Netsh -r connects to remote computer.

                  Powershell's range operator is just what this problem needs. Bonus points for single-liner.
                  Code:
                  10..20 | % {iex ([string]::format("netsh interface ipv4 add address 10.10.10.{0} 255.255.255.0",$_))}
                  -vP
                  Hi Von Pryz,

                  thanks for replying to this thread, all of us can get benefits from your Powershell-ing technique.

                  here it is another example that works too:

                  Code:
                  #setup collection of IP address strings, include original IP
                  $ips = 1..100 | %{ "10.2.1.$_" }
                  
                  #also subnet masks, need as many as IP addresses
                  $masks = 1..100 | %{ "255.255.255.0" }
                  
                  #get the NIC
                  $nic = Get-WMIObject win32_networkadapterconfiguration -computer VM-Simulator1 | where { $_.IPAddress -contains "10.2.1.1" }
                  
                  #set addresses
                  $nic.EnableStatic($ips,$masks)
                  one more thing to add, the one liner that you provide can only works if the IP address range of the current static assigned is the same with the IP address range that we want to have, otherwise you could get:

                  Code:
                  The following command was not found: interface ipv4 add address 10.10.10.10 255.255.255.0.
                  Last edited by Albertwt; 13th April 2010, 00:31.

                  Comment

                  Working...
                  X