문제

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

도움이 되었습니까?

해결책

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.
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top