Get connection/disconnected duration from net adapter

This topic contains 7 replies, has 2 voices, and was last updated by  Max Kozlov 2 months, 3 weeks ago.

  • Author
    Posts
  • #71762

    Alexander Johansson
    Participant

    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.

  • #71782

    Max Kozlov
    Participant
    Get-CimInstance -ClassName Win32_NetworkAdapter| select Name, TimeOfLastReset
    
  • #71801

    Alexander Johansson
    Participant

    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.

  • #71813

    Max Kozlov
    Participant

    (Get-Date) – $i.TimeOfLastReset ?

  • #71821

    Alexander Johansson
    Participant

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

  • #71831

    Max Kozlov
    Participant

    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
    
  • #71842

    Alexander Johansson
    Participant

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

  • #71863

    Max Kozlov
    Participant

    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

You must be logged in to reply to this topic.