Get-NetIPAddress

Get IPAddress configuration.

Syntax
      Get-NetIPAddress [[-IPAddress] String[]>] [-InterfaceIndex UInt32[]] [-InterfaceAlias String[]]
         [-AddressFamily AddressFamily[]] [-Type Type[]] [-PrefixLength Byte[]] [-PrefixOrigin PrefixOrigin[]]
            [-SuffixOrigin SuffixOrigin[]>] [-AddressState AddressState[]] [-ValidLifetime TimeSpan[]]
               [-PreferredLifetime TimeSpan[]>] [-SkipAsSource Boolean[]] [-AssociatedIPInterface CimInstance]
                  [-PolicyStore String] [-IncludeAllCompartments] [-CimSession CimSession[]] [-ThrottleLimit Int32]
                     [-AsJob] [CommonParameters]

Key
   -AddressFamily
      Gets the IP address configurations that match the address families.
      Accepted values: IPv4, IPv6  (either or both as an array).

   -AddressState
      An array of duplicate address detection (DAD) state values for the IP address.
      Use this parameter to filter the output based on addresses that are valid and available for use.
      Accepted values: 
         -- Invalid.    IP address configuration information for addresses that are not valid and will not be used.

         -- Tentative.  IP address configuration information for addresses that are not used for communication,
                        as the uniqueness of those IP addresses is being verified.

         -- Duplicate.  IP address configuration information for addresses for which a duplicate IP address has been
                        detected and the current IP address will not be used.

         -- Deprecated. IP address configuration information for addresses that will no longer be used to establish new
                        connections, but will continue to be used with existing connections.

         -- Preferred.  IP address configuration information for addresses that are valid and available for use.

   -AsJob
      Run the cmdlet as a background job. Use this parameter to run commands that take a long time to complete.

   -AssociatedIPInterface
      Specify an IP interface as a CIM object. To obtain an IP interface, use the Get-NetIPInterface cmdlet.

   -CimSession
      Run the cmdlet in a remote session or on a remote computer.
      Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet.
      The default is the current session on the local computer.

   -IncludeAllCompartments
      Indicates that the cmdlet includes addresses from all configured network compartments.
      If you do not specify this parameter, the cmdlet gets only addresses in the default network compartment.

   -InterfaceAlias
      Specifies an array of aliases of network interfaces. The cmdlet gets IP addresses that match the aliases.

   -InterfaceIndex
      Specifies an array of indexes of network interfaces. The cmdlet gets IP addresses that match the indexes.

   -IPAddress
      Specifies an array of IPv4 or IPv6 addresses.

   -PolicyStore
      Specifies a PolicyStore value.
      Accepted values:
          ActiveStore     The IP address information is valid.
          PersistentStore The computer saves IP address information across restarts.
                          When the computer restarts, it copies the saved settings to the ActiveStore.
      The default value is ActiveStore.

   -PreferredLifetime
      Specifies an array of values of preferred lifetimes, as TimeSpan objects, for an IP address.
      To obtain a TimeSpan object, use the New-TimeSpan cmdlet.

   -PrefixLength
      Specifies an array of prefix lengths. This parameter defines the local subnet size, and is also known as a subnet mask.

   -PrefixOrigin
      Specifies an array of origins for address prefixes. IP addresses are divided into two parts, the prefix and the suffix.
      The address prefix identifies the network portion of an IP address, and the address suffix identifies the host portion.
      Accepted values:
         Manual      The IP address prefix was manually specified. 
         WellKnown   The IP address prefix is from a well-known source. 
         DHCP        The IP address prefix was provided by DHCP settings. 
         RouterAdvertisement  The IP address prefix was obtained through a router advertisement (RA). 
         Other       The IP address prefix was obtained from another source, such as a VPN.

   -SkipAsSource
      Indicates whether an address is a primary IP address.
      This parameter identifies the primary IP address for outgoing traffic in a multiple IP address scenario.
      If this parameter is set to True, the addresses are not used for outgoing traffic and are not registered in DNS.

  -SuffixOrigin
      Specifies an array of origins for address suffixes.
      IP addresses are divided into two parts, the prefix and the suffix.
      The address prefix identifies the network portion of an IP address, and the address suffix identifies the host portion. 
      Accepted values:
         Manual    The IP address suffix was manually specified.
         WellKnown The IP address suffix is from a well-known source.
         DHCP      The IP address suffix was provided by DHCP settings.
         Link      The IP address suffix was obtained from the link-layer address.
         Random    The IP address suffix was obtained from a random source.
         Other     The IP address suffix was obtained from another source, such as a VPN.

   -ThrottleLimit
      Specifies the maximum number of concurrent operations that can be established to run the cmdlet.
      If this parameter is omitted or a value of 0 is entered, then PowerShell calculates an optimum throttle limit for
      the cmdlet based on the number of CIM cmdlets that are running on the computer.
      The throttle limit applies only to the current cmdlet, not to the session or to the computer.

   -Type
      Specifies an array of IP address types.
      Accepted values: Unicast or Anycast, default = Unicast.

   -ValidLifetime
      Specifies an array of values for valid lifetimes, as TimeSpan objects, for an IP address.
      To obtain a TimeSpan object, use the New-TimeSpan cmdlet.

The Get-NetIPAddress cmdlet gets the IP address configuration, such as IPv4 addresses, IPv6 addresses and the IP interfaces with which addresses are associated. Without parameters, this cmdlet gets the entire IP address configuration for the computer.

Examples

Get the currently connected IPv4 IP address for the local machine:

PS C:\> $ip4 = Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $(Get-NetConnectionProfile | Select-Object -ExpandProperty InterfaceIndex) | Select-Object -ExpandProperty IPAddress

Get the currently connected IPv6 IP address for the local machine:

PS C:\> $ip6 = Get-NetIPAddress -AddressFamily IPv6 -InterfaceIndex $(Get-NetConnectionProfile | Select-Object -ExpandProperty InterfaceIndex) | Select-Object -ExpandProperty IPAddress

Get both the currently connected IPv4 and IPv6 IP addresses for the local machine and place on the clipboard:

PS C:\> Get-NetIPAddress -InterfaceIndex $(Get-NetConnectionProfile | Select-Object -ExpandProperty InterfaceIndex) | Select-Object -ExpandProperty IPAddress | set-clipboard

Get IP address information and format the output:

PS C:\> Get-NetIPAddress | Format-Table

Get hostname from IP:

PS C:\> [System.Net.Dns]::GetHostEntry('ip_address').HostName

Get IP address information by the interface index:

PS C:\> Get-NetIPAddress -InterfaceIndex 12

Get IP address information and sort the output by the interface index:

PS C:\> Get-NetIPAddress | Sort-Object -Property InterfaceIndex | Format-Table

Get IP address configuration for IP addresses that have a ValidLifetime of less than one day:

PS C:\> Get-NetIPAddress | `
Where-Object -FilterScript { $_.ValidLifetime -Lt ([TimeSpan]::FromDays(1)) }

Get IP address information and sort the output by the interface index:

PS C:\> Get-NetIPAddress | `
Where-Object -FilterScript { $_.ValidLifetime -Eq ([TimeSpan]::MaxValue) }

“You may say I’m a dreamer, but I’m not the only one. I hope someday you’ll join us...” ~ John Lennon

Related PowerShell Cmdlets

Get-NetRoute
New-NetIPAddress
Remove-NetIPAddress
Set-NetIPAddress
Set-NetTCPSetting - Modify a TCP setting.
Test-NetConnection - Display diagnostic information for a connection.
Script to resolve IP addresses and the program maintaining each connection - Idera.com


 
Copyright © 1999-2024 SS64.com
Some rights reserved