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.
Get-CimInstance -ClassName Win32_NetworkAdapter| select Name, TimeOfLastReset
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.
(Get-Date) - $i.TimeOfLastReset ?
If you unplug the network cable and the network card becomes disconnected and then insert it again, the value stays the same.
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
I’m sorry, that doesn’t give me the name of the connected NICs.
I really do appreciate your help though.
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