Set NetAdapter - PowerShell


Overview

Set-NetAdapter modifies the settings of network adapters on local and remote computers. It allows network administrators to configure parameters such as IP addresses, subnet masks, and DNS servers. This command is commonly used for network troubleshooting, IP assignment, and enabling or disabling adapters.

Syntax

Set-NetAdapter [[-Name] <String>] -InterfaceIndex <UInt32> [-AddressFamily <AddressFamily>]
               [-IPAddress <IPAddress>] [-SubnetMask <IPAddress>] [-DefaultGateway <IPAddress>] [-DNSServer <IPAddress>]
               [-AlternateDNSServer <IPAddress>] [-Description <String>] [-EnableDHCP <Boolean>]
               [-MACAddress <PhysicalAddress>] [-Name <String>] [-InterfaceDescription <String>] [-Status <NetAdapterStatus>]
               [-Confirm] [-WhatIf] [-PassThru]

Options/Flags

  • -AddressFamily: Specifies the address family of the IP address to be configured. By default, it’s IPv4.
  • -IPAddress: Sets the IPv4 or IPv6 address for the specified adapter.
  • -SubnetMask: Defines the subnet mask for the specified IP address.
  • -DefaultGateway: Sets the default gateway IP address.
  • -DNSServer: Specifies the primary DNS server IP address.
  • -AlternateDNSServer: Sets the secondary DNS server IP address.
  • -Description: Allows you to set a custom description for the network adapter.
  • -EnableDHCP: Enables or disables DHCP for the specified adapter. True enables DHCP, while False disables it.
  • -MACAddress: Sets the MAC address of the network adapter. Use a physical address in the format XX-XX-XX-XX-XX-XX.
  • -Name: Specifies the friendly name of the network adapter.
  • -InterfaceDescription: Sets the description of the adapter interface.
  • -Status: Sets the status of the network adapter. Valid options are Enabled or Disabled.
  • -Confirm: Prompts for confirmation before executing the command.
  • -WhatIf: Shows what would happen if the command were executed without actually making any changes.
  • -PassThru: Returns the modified network adapter object after the command execution.

Examples

Example 1: Set the IP address and subnet mask of an adapter

Set-NetAdapter -Name "Ethernet" -IPAddress "192.168.1.10" -SubnetMask "255.255.255.0"

Example 2: Disable DHCP and set a static IP address

Set-NetAdapter -Name "Wi-Fi" -EnableDHCP $false -IPAddress "10.0.0.10" -SubnetMask "255.255.255.0" -DefaultGateway "10.0.0.1"

Example 3: Set a custom DNS server and description

Set-NetAdapter -Name "Ethernet" -DNSServer "8.8.8.8" -AlternateDNSServer "8.8.4.4" -Description "Custom DNS Configuration"

Example 4: Retrieve the modified adapter object

$adapter = Set-NetAdapter -Name "Ethernet" -Status Enabled -PassThru
$adapter.Status
Enabled

Common Issues

  • Adapter not found: Ensure the specified adapter name or index exists on the system.
  • Access denied: You may need elevated privileges (run PowerShell as administrator) to modify adapter settings.
  • Invalid IP or subnet mask: Verify that the specified IP address and subnet mask are valid for the target adapter.

Integration

Set-NetAdapter can be used in conjunction with other network-related commands, such as:

  • Get-NetAdapter: Retrieve information about network adapters.
  • Enable-NetAdapter: Enable a disabled network adapter.
  • Disable-NetAdapter: Disable an enabled network adapter.
  • New-NetIPAddress: Add an additional IP address to an adapter.
  • Remove-NetIPAddress: Remove an IP address from an adapter.