Powershell为适配器分配多个IP地址

时间:2011-09-23 16:27:02

标签: networking powershell wmi ip adapter

我想编写一个powershell脚本来创建一个环回适配器并为其分配多个ip地址。您可以看到我在哪里获得适配器,然后根据它是否已经存在而使用if语句。在if语句中,我将要创建并命名适配器。之后我想为它分配多个IP地址。

我手动创建了适配器。我的代码试图分配IP地址。但是,IP地址似乎没有被分配。另外,如果你知道如何创建环回适配器,请告诉我。

cls
# Get-wmiobject win32_NetworkAdapter 
$networkAdapter = Get-WMIObject win32_NetworkAdapter | where{$_.ServiceName -eq 'msloop'}

if(!$networkAdapter)
{
    #"null"

}

"The following IP Addresses are already assigned:"
#Get-WMIObject win32_NetworkAdapterConfiguration -filter "IPEnabled = $true" | Foreach-Object { $_.IPAddress }

$adapterIndex = $networkAdapter.Index;
$adapterConfig = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter "Index = $adapterIndex AND ipenabled = 'true'");
$adapterConfig.IPAddress

$ip = @("192.168.200.1", "192.168.200.2", "192.168.200.3", "192.168.200.4", "192.168.200.5",  "192.168.200.6")
$dns = "255.255.255.0"
$adapterConfig.EnableStatic($ip, $dns)
$adapterConfig.IPAddress

0 个答案:

没有答案