Get NetAdapter - PowerShell


Overview

Get-NetAdapter is a PowerShell command that allows administrators to view and manage network adapters on Windows systems. It provides comprehensive information about each adapter, including properties such as status, speed, MAC address, and IP configuration.

Syntax

Get-NetAdapter [[-Name] <string>] [-InterfaceAlias <string>] [-Physical] [-Virtual] [-MacAddress <string>] [-InterfaceType <string>] [-DisableDhcp] [-EnableRouting] [-SetDNSServer <string[]>] [-PassThru] [-WhatIf] [-Confirm] [-Debug]

Options/Flags

  • -Name: Specifies the name of the network adapter to be retrieved.
  • -InterfaceAlias: Retrieves the network adapter based on its interface alias.
  • -Physical: Limits the search to only physical network adapters.
  • -Virtual: Limits the search to only virtual network adapters.
  • -MacAddress: Retrieves the network adapter based on its MAC address.
  • -InterfaceType: Retrieves the network adapter based on its interface type (e.g., ethernet, wireless).
  • -DisableDhcp: Disables DHCP on the specified network adapter.
  • -EnableRouting: Enables routing on the specified network adapter.
  • -SetDNSServer: Sets the DNS servers for the specified network adapter.
  • -PassThru: Returns a NetAdapter object instead of an object of type PSObject. This is useful for piping the output to other commands.
  • -WhatIf: Shows what would happen if the command were run without actually making any changes.
  • -Confirm: Prompts the user for confirmation before executing the command.
  • -Debug: Provides detailed debugging information about the command’s execution.

Examples

  • Get all network adapters:
Get-NetAdapter
  • Get specific network adapter by name:
Get-NetAdapter -Name "Ethernet"
  • Get network adapter by MAC address:
Get-NetAdapter -MacAddress "00:11:22:33:44:55"
  • Disable DHCP on a specific network adapter:
Get-NetAdapter -Name "Ethernet" | Disable-NetAdapterDhcp
  • Set DNS servers on a network adapter:
Get-NetAdapter -Name "Ethernet" | Set-DnsClientServerAddress -ServerAddresses "8.8.8.8", "8.8.4.4"

Common Issues

  • Network adapter not found: Ensure that the specified adapter name, interface alias, or MAC address is correct.
  • Permission denied: The current user may not have sufficient permissions to view or modify network adapter settings.
  • DHCP configuration failure: Make sure that the DHCP server is reachable and that the network adapter is configured to use DHCP.

Integration

Get-NetAdapter can be integrated with other PowerShell commands for advanced tasks, such as:

  • Using Set-NetAdapter to modify network adapter properties.
  • Combining with New-NetIPAddress to assign IP addresses to adapters.
  • Using Get-NetIPConfiguration to retrieve detailed IP configuration information.
  • Add-NetAdapter
  • Disable-NetAdapterDhcp
  • Enable-Routing
  • Set-NetAdapter