New NetIPAddress - PowerShell


Overview

The New-NetIPAddress cmdlet creates a new IP address on a specified network interface, considering network address translation (NAT) settings. This cmdlet is used to add more IP addresses to a NIC that may be operating in a static or dynamic environment.

Syntax

New-NetIPAddress [-InterfaceAlias] <String> [-IPAddress] <IPAddress> [-AddressFamily] <AddressFamily> [-PrefixLength] <Int32> [-DefaultGateway] <IPAddress> [-Metric] <Int32> [-Publish] [-SkipAsSource] [-Transient] [-ProtectionLevel] <NetProtectionLevel> [-Confirm] [-WhatIf] [-OutVariable] <String>

Options/Flags

  • InterfaceAlias: Specifies the alias of the network interface on which to create the IP address.
  • IPAddress: Specifies the IP address to be created.
  • AddressFamily: Specifies the address family of the IP address. Valid values are IPv4 and IPv6.
  • PrefixLength: Specifies the prefix length of the subnet mask for the IP address. For IPv4 addresses, the default is 24. For IPv6 addresses, the default is 64.
  • DefaultGateway: Specifies the default gateway for the IP address.
  • Metric: Specifies the metric for the IP address. The metric determines the priority of the IP address when multiple IP addresses are available on the same interface.
  • Publish: Specifies whether or not to publish the IP address to the network.
  • SkipAsSource: Specifies whether or not to skip the IP address as a source for outgoing traffic.
  • Transient: Specifies whether or not to create a transient IP address. Transient IP addresses are not stored persistently and are lost when the computer is restarted.
  • ProtectionLevel: Specifies the protection level for the IP address. Valid values are Unrestricted, Authenticated, and Encrypted.

Examples

Example 1: Create a new IPv4 address on the wired network adapter.

New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 192.168.1.10 -PrefixLength 24

Example 2: Create a new IPv6 address on the wireless network adapter.

New-NetIPAddress -InterfaceAlias "Wi-Fi" -IPAddress 2001:db8::1 -PrefixLength 64

Example 3: Create a new IP address with a specific metric.

New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 192.168.1.11 -PrefixLength 24 -Metric 10

Common Issues

  • Ensure that the specified network interface is valid and exists on the computer.
  • Verify that the specified IP address is not already in use on the network.
  • Check that the specified prefix length is valid for the address family being used.

Integration

New-NetIPAddress can be combined with other PowerShell cmdlets to perform more complex tasks, such as:

  • Get-NetIPAddress: Retrieve information about existing IP addresses.
  • Remove-NetIPAddress: Remove an IP address from a network interface.
  • Set-NetIPAddress: Modify the properties of an existing IP address.