title: How to subscribe to an event through Get-WinEvent in powershell?
body: <p>I'm trying to listen for a specific log entry in the windows event log, that signifies that the computer has connected to the internet:</p>
  <pre><code>LogName: Microsoft-Windows-NetworkProfile/Operational
  Event ID: 10000
  </code></pre>
  <p>I found some code from an existing SO <a href="https://stackoverflow.com/questions/15959904/waiting-for-a-specific-event-in-powershell">question</a> and tried to adapt it for my purpose. The problem is that I can seemingly only find my event using <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/Get-WinEvent?view=powershell-7" rel="nofollow noreferrer"><code>Get-WinEvent</code></a> instead of the suggested (deprecated) <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-eventlog?view=powershell-5.1" rel="nofollow noreferrer"><code>Get-EventLog</code></a>.</p>
  <p>The <a href="https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.entrywritten?view=dotnet-plat-ext-3.1" rel="nofollow noreferrer"><code>EntryWritten</code></a> event does not seem to exist for <code>WinEvent</code> entries, is there some other event I can 'subscribe' to to listen for new entries for my event? Or should I try some other method?</p>
  <pre><code>
  $networklog = Get-WinEvent -LogName 'Microsoft-Windows-NetworkProfile/Operational'
  
  Register-ObjectEvent -InputObject $networklog -SourceIdentifier NewEventLogEntry -EventName EntryWritten -Action {
  
      $entry = $event.SourceEventArgs.Entry
  
      if($entry.EventID -eq 10000) {
          # check_url($url)
          Write-Host &quot;Connected&quot;
      }
      else { 
          Write-Host &quot;Something else&quot;
      }
  }
  </code></pre>
  <p>My end goal is to have a simple script running continuously that calls a function as soon as a connection to a specific url is available. Any other suggestions for achieving this would be greatly appreciated as I feel I'm in rather deep water having not touched powershell previously.</p>