title: Adding additional IP addresses on windows server
body: <p>Is it possible to use powershell or use a bat script under <code>C:\Windows\addExtraIP.bat</code> that uses a number of arguments to add IP addresses to the interface/connection.</p>
  
  <p>The idea is to use something like:</p>
  
  <p><code>addExtraIP.bat 192.168.1.2 192.168.1.3 192.168.1.4 and so on..</code></p>
  
  <p>This <code>addExtraIP.bat</code> script should be called/invoked from remote. I read something about <a href="https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/running-remote-commands?view=powershell-5.1" rel="nofollow noreferrer">PowerShell remoting</a>, but not sure where to start or what to do.</p>
  
  <p>Any idea? Thanks in advance!</p>
  
  <p>EDIT:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>This script is what I am trying to use. How would I call the script as mentioned above?</p>
  
  <p>EDIT 2:</p>
  
  <pre><code>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'
  </code></pre>
  
  <p>So how would I set this in a script and run regardless how much arguments are passed to it? </p>