0

I am trying to assign multiple ips to a NIC on a windows server. Is there any way I could dynamically generate the ip addresses and assign it to the NIC

1 Answer 1

2

You want to call the EnableStatic method on the instance of the Win32_NetworkAdapterConfiguration WMI class for the network interface you want to configure.

uint32 EnableStatic(
  [in]  string IPAddress[],
  [in]  string SubnetMask[]
);

You can see above it takes two parameters. A string array of IP addresses and a string array of subnet masks.

It will return an status code. 0 indicates success.

Here is PowerShell example code:

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "IPEnabled=true" | 
    ForEach-Object {
        $result = $_.EnableStatic(("192.168.1.10","10.0.0.10"),("255.255.255.0","255.0.0.0"))
        if ($result -ne 0) {
            # handle non-successful response code here.
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.