在windows服务器上添加其他IP地址

在windows服务器上添加其他IP地址,windows,powershell,batch-file,scripting,Windows,Powershell,Batch File,Scripting,是否可以在C:\Windows\addExtraIP.bat下使用powershell或bat脚本,该脚本使用多个参数向接口/连接添加IP地址 我们的想法是使用如下内容: addExtraIP.bat 192.168.1.2 192.168.1.3 192.168.1.4等等。 这个addExtraIP.bat脚本应该从远程调用。我读了一些关于,但不确定从哪里开始或做什么 有什么想法吗?提前谢谢 编辑: 这个脚本就是我正在尝试使用的。我如何调用上面提到的脚本 编辑2: function Set-

是否可以在
C:\Windows\addExtraIP.bat
下使用powershell或bat脚本,该脚本使用多个参数向接口/连接添加IP地址

我们的想法是使用如下内容:

addExtraIP.bat 192.168.1.2 192.168.1.3 192.168.1.4等等。

这个
addExtraIP.bat
脚本应该从远程调用。我读了一些关于,但不确定从哪里开始或做什么

有什么想法吗?提前谢谢

编辑:

这个脚本就是我正在尝试使用的。我如何调用上面提到的脚本

编辑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'

那么,我应该如何在脚本中设置它并运行它,而不管有多少参数传递给它

使用新NetIPAddress的基本foreach循环

param([array]$IPs)

Foreach ($IP in $IPs)
{
    New-NetIPAddress -InterfaceIndex 12 -IPAddress $IP -PrefixLength 24 -DefaultGateway 192.168.0.5
}
然后像这样打电话:

ScriptName.ps1 -IPs 192.168.0.1,192.168.0.2

是的,但最好使用包含IP地址的文本文件。如果您没有发布需要帮助的当前脚本,您的问题将是一个直接的代码请求,并且在此处脱离主题。您的问题非常模糊,没有实际的代码,因此我们不知道您试图做什么或如何做。你真的需要阅读,因为这将帮助你找出你的问题遗漏了什么以及为什么被否决。我已经更新了这个问题。我理解那些反对票,但整个Windows系统对我来说是全新的。很长一段时间以来,我需要使用windows机器。同样,我们的想法是向接口添加多个IP,就像Linux使用
eth0:1、eth0:2等等。看看@JamesC。我看到了
新的NetIPAddress-InterfaceIndex 12-IPAddress 192.168.0.1-PrefixLength 24-DefaultGateway 192.168.0.5
,但如何使用
for循环
并将
192.168.0.1
替换为参数?此外,还应远程调用此
ps1
脚本。谢谢!我先去本地看看。我最后需要使用
chef knife
ScriptName.ps1 -IPs 192.168.0.1,192.168.0.2