How to restart network adapters using PowerShell

One of the challenges of network administration is to manage the network adapters. Sometimes, you may need to change the settings of an adapter. Such as its IP address, subnet mask, or gateway, without rebooting the system. In such cases, you can use this PowerShell script to accomplish that. The script has 2 parameters:
First is the name of the adapter
Second, is the new settings.
During the execution, the script uses the Get-NetAdapter and Set-NetIPInterface cmdlets to apply the changes. Additionally, the script checks for errors and displays a confirmation message when the operation is successful.

This script is the second part of my disable IPV6 script that is available here (How to disable IPV6 protocols on all adapters using Powershell).

Here is a quick way to restart network adapters using Microsoft PowerShell.

This is how the script works line by line:

  1. We are using  Get-NetAdapter cmdlet to obtain a list of all available network adapters.
  2. This will be passed to the foreach to iterate through and store each adapter in the adapter variable.
  3. Write-Host will display the adapter name using the Name property.
  4. We will also use the same Name property to Disable-NetAdapter.
  5. Finally, we will  Enable-NetAdapter cmdlets to turn them off and on. In this example, I am using -Confirm parameter to suppress user input.
example:
foreach ($adapter in Get-NetAdapter) {
    $an=$adapter.Name;
    Write-Host "Restarting Adapter: $an";
    Disable-NetAdapter -Name $adapter.Name -Confirm:$false;
    Enable-NetAdapter -Name $adapter.Name -Confirm:$false;
}
Write-Host "Done..."

Hope you find this useful.

note:

When writing new scripts always use Get-Help <cmdlet> to find more information about any cmdlet.