Author Posts

May 31, 2017 at 9:24 am

Hello,

I wonder if there is some way, from PowerShell, to see for how long a net adapter has been connected/disconnected.
Like when you are double clicking a net adapter in the control panel and you can see the connection duration time.

I've tried to explore MSFT_NetAdapter and Win32_NetworkAdapter but with no luck.

I need this because I want to make a script that disables a NIC when it has had the status "Disconnected" for a specified period of time.

Do you have any other ideas? All help is welcome.

Thanks in advance.

May 31, 2017 at 12:51 pm

Get-CimInstance -ClassName Win32_NetworkAdapter| select Name, TimeOfLastReset

May 31, 2017 at 2:02 pm

Thank you for your reply.

I'm sorry to say that the value returned from that command only reports the reset of the device from a reboot or system startup.

May 31, 2017 at 2:38 pm

(Get-Date) – $i.TimeOfLastReset ?

May 31, 2017 at 4:02 pm

If you unplug the network cable and the network card becomes disconnected and then insert it again, the value stays the same.

May 31, 2017 at 6:02 pm

sorry I don't try to unplug cable, may be events can help ?

Get-WinEvent -FilterHashtable @{ProviderName='Microsoft-Windows-NetworkProfile'; id=10000,10001} -MaxEvents 10

June 1, 2017 at 7:31 am

I'm sorry, that doesn't give me the name of the connected NICs.
I really do appreciate your help though.

June 1, 2017 at 11:43 am

Hmm. Then may be combination of events with further analysis
4001, 4002, 10000, 10001
4001/4002 contains adapter guid, and 10001/10001 – network state
and 'Microsoft-Windows-Windows Firewall With Advanced Security' – 2010