Can Win32_NetworkAdapterConfiguration.EnableStatic() be used to set more than one IP address?

Posted by Andrew J. Brehm on Stack Overflow See other posts from Stack Overflow or by Andrew J. Brehm
Published on 2010-05-26T15:39:13Z Indexed on 2010/05/26 15:41 UTC
Read the original article Hit count: 246

Filed under:
|
|

I ran into this problem in a Visual Basic program that uses WMI but could confirm it in PowerShell. Apparently the EnableStatic() method can only be used to set one IP address, despite taking two parameters IP address(es) and subnetmask(s) that are arrays.

I.e.

$a=get-wmiobject win32_networkadapterconfiguration -computername myserver

This gets me an array of all network adapters on "myserver". After selecting a specific one ($a=$a[14] in this case), I can run $a.EnableStatic() which has this signature

System.Management.ManagementBaseObject EnableStatic(System.String[] IPAddress, System.String[] SubnetMask)

I thought this implies that I could set several IP addresses like this:

$ips="192.168.1.42","192.168.1.43"
$a.EnableStatic($ips,"255.255.255.0")

But this call fails. However, this call works:

$a.EnableStatic($ips[0],"255.255.255.0")

It looks to me as if EnableStatic() really takes two strings rather than two arrays of strings as parameters.

In Visual Basic it's more complicated and arrays must be passed but the method appears to take into account only the first element of each array.

Am I confused again or is there some logic here?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about powershell