I want to write a powershell script to create a loopback adapter and assign multiple ip addresses to it. You can see where I am getting the adapter and then have an if statement that works based on whether or not it already exists. In the if statement I'll want to create and name the adapter. Following that I want to assign multiple IP addresses to it.
I manually created the adapter. My code is trying to assign ip addresses. However, the ip addresses don't seem to be getting assigned. Also, if you know how to create the loopback adapter in the first place let me know.
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
开发者_StackOverflow$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
精彩评论