上添加额外的IP地址是否可以使用PowerShell或使用多个参数,以IP地址添加到接口/连接C:\Windows\addExtraIP.bat
下使用蝙蝠脚本。Windows服务器
的想法是使用类似:
addExtraIP.bat 192.168.1.2 192.168.1.3 192.168.1.4 and so on..
这addExtraIP.bat
脚本应该叫/远程调用。我读了一些关于PowerShell remoting的信息,但不确定从哪里开始或做什么。
有什么想法?提前致谢!
编辑:
function Set-IPAddress {
param( [string]$networkinterface = "Local Area Connection",
[string]$ip,
[string]$mask,
[string]$gateway,
[string]$dns1 = "8.8.8.8",
[string]$dns2 = "8.8.4.4",
[string]$registerDns = "TRUE"
)
#Start writing code here
$dns = $dns1
if($dns2){$dns =$dns1,$dns2}
$index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex
$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}
$NetInterface.EnableStatic($ip, $mask)
$NetInterface.SetGateways($gateway)
$NetInterface.SetDNSServerSearchOrder($dns)
$NetInterface.SetDynamicDNSRegistration($registerDns)
}
Set-IPAddress
这个脚本是什么,我尝试使用。我如何称呼上述脚本?
编辑2:
function Set-IPAddress {
param(
[string]$networkinterface = "Local Area Connection",
[string[]]$ip,
[string[]]$mask,
[string]$gateway,
[string]$dns = @("10.210.1.101", "10.210.1.130"),
[bool]$registerDns = $true
)
$index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex
$NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}
$NetInterface.EnableStatic($ip, $mask)
$NetInterface.SetGateways($gateway)
$NetInterface.SetDNSServerSearchOrder($dns)
$NetInterface.SetDynamicDNSRegistration($registerDns)
}
Set-IPAddress -IP '1.2.3.4', '2.3.4.5' -Mask '255.255.255.0', '255.255.255.0'
所以我怎么会设置这个在脚本并运行,无论有多少参数传递给它?使用New-NetIPAddress
是的,但它可能是最好使用含IP地址的文本文件。如果您没有发布当前的脚本需要帮助,那么您的问题将是一个直接的代码请求,并且在这里脱离主题。 – Compo
你的问题是很模糊的,不包含任何实际的代码,所以我们不知道是什么,或者怎么样,你正在尝试做的。你真的需要阅读[如何提问](http://stackoverflow.com/questions/how-to-ask),因为这将帮助你找出你的问题是缺少,为什么它被downvoted。 –
我已经对这个问题进行了更新。我了解倒票,但这整个Windows的东西对我来说是新的。很久以前我需要使用Windows机器。同样,这个想法是为接口添加多个IP,就像Linux使用'eth0:1,eth0:2 ...'等一样。 – val0x00ff