# Get connection/disconnected duration from net adapter

**URL:** <https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730>\
**Category:** PowerShell Help\
**Created:** [May 31, 2017, 3:54am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730 "2017-05-31T03:54:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexander-johansson](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@alexander-johansson](https://forums.powershell.org/u/alexander-johansson)\
**Post date:** [May 31, 2017, 3:54am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/1 "2017-05-31T03:54:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [May 31, 2017, 7:21am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/2 "2017-05-31T07:21:33Z")

</div>

```
Get-CimInstance -ClassName Win32_NetworkAdapter| select Name, TimeOfLastReset
```

---

<div class="post-metadata">

**Author:** ![alexander-johansson](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@alexander-johansson](https://forums.powershell.org/u/alexander-johansson)\
**Post date:** [May 31, 2017, 8:32am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/3 "2017-05-31T08:32:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [May 31, 2017, 9:08am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/4 "2017-05-31T09:08:30Z")

</div>

(Get-Date) - $i.TimeOfLastReset ?

---

<div class="post-metadata">

**Author:** ![alexander-johansson](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@alexander-johansson](https://forums.powershell.org/u/alexander-johansson)\
**Post date:** [May 31, 2017, 10:32am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/5 "2017-05-31T10:32:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [May 31, 2017, 12:32pm UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/6 "2017-05-31T12:32:47Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![alexander-johansson](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@alexander-johansson](https://forums.powershell.org/u/alexander-johansson)\
**Post date:** [June 1, 2017, 2:01am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/7 "2017-06-01T02:01:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [June 1, 2017, 6:13am UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/8 "2017-06-01T06:13:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:38pm UTC](https://forums.powershell.org/t/get-connection-disconnected-duration-from-net-adapter/8730/9 "2024-05-16T20:38:41Z")

</div>

Closed on May 16, 2024, 8:38pm UTC


