Server 2012, Powershell 3.0.
I'm doing some work that requires automating the enabling and disabling of network adapters. Here is an example of what I see when I run Get-NetAdapter
:
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
Slot 0 Port 4 HP NC382i DP Multifunction Gigabi...#53 15 Not Present 11-80-1B-94-2A-82 0 bps
Slot 0 Port 2 (TM-2) HP NC382i DP Multifunction Gigabi...#51 14 Up 11-80-1B-94-27-72 1 Gbps
Team 1 (Team) Microsoft Network Adapter Multiplexo... 17 Up 11-80-1B-94-2A-72 1 Gbps
Slot 0 Port 3 HP NC382i DP Multifunction Gigabi...#52 13 Disabled 11-80-1B-94-2A-80 1 Gbps
Slot 0 Port 1 (TM-1) HP NC382i DP Multifunction Gigabi...#50 12 Up 11-80-1B-94-2A-70 1 Gbps
Notice that the Status attribute is not binary. It could be Up, Disabled, or Not Present.
When I run Enable-NetAdapter
on a NIC whose status is 'Not Present,' the command silently returns, no error output, but it does not enable the NIC. I then enabled the NIC manually by right-clicking its icon in the Control Panel and choosing Enable. Its status was now Enabled with a Status of Up.
Then I ran Disable-NetAdapter
on the NIC. Its status was now 'Disabled.'
Now, the Enable-NetAdapter
Cmdlet worked as expected and turns the NIC on.
- So what was 'Not Present' and why did Powershell fail to enable the NIC when it was in that state, but I had no problems enabling it via the GUI, but now it seems to only flip back and forth between Enabled and Disabled?
- How do I get 'Not Present' back if I wanted to?
- How do I enable a NIC with Powershell when it's in a 'Not Present' state?
The
Not Present
state comes from the InterfaceOperationalStatus of the MSFT_NetAdapter class. It's used for network interfaces that are known but currently not available due to the hardware missing for example. Another reason could be that the driver for the hardware was just not loaded at the time. If you deactivate the NIC using the device manager, the driver will unload. Virtual NICs, of VMware Workstation for example, will get deativated and show up as "Not Present" until you boot a virtual machine that uses them.Powershell only handles interfaces not the NICs themselves using
Enable-NetAdapter
,Disable-NetAdapter
andGet-NetAdapter
. If the device was deactiated then you probably have to use the device management cmdletsIf you turned off NIC (device) it can be shown as "Status: Not Present". To enable device you just need to use Get-WmiObject command:
$wmi = Get-WmiObject -Class Win32_NetworkAdapter -filter "Name LIKE '%Adapter%'"
$wmi.enable()
Source: http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/13/enabling-and-disabling-network-adapters-with-powershell.aspx