title: How to detect an active VPN connection with a specific name
body: <p>I found an <a href="https://smsagent.wordpress.com/2016/06/10/detect-an-active-vpn-adapter-during-configmgr-deployments/" rel="nofollow noreferrer">article</a> which lists several ways to detect an active VPN: </p>
  
  <ol>
  <li><p>Using Win32_NetworkAdapter:</p>
  
  <pre><code>Get-WmiObject -Query "Select * from Win32_NetworkAdapter 
  where Name like '%VPN%' and NetEnabled='True'"
  </code></pre></li>
  <li><p>Using Win32_NetworkAdapterConfiguration:</p>
  
  <pre><code>Get-WmiObject -Query "Select * from Win32_NetworkAdapterConfiguration 
  where Description like '%VPN%' and IPEnabled='True'"
  </code></pre></li>
  <li><p>Checking the presence of an active PPP adapter</p>
  
  <pre><code>ipconfig | Select-String 'PPP adapter'
  </code></pre></li>
  <li><p>Checking the IPv4 routing table</p>
  
  <pre><code>Get-WmiObject -Query "Select * from Win32_IP4RouteTable 
  where Name like '10.0.99.%' or Name like '10.15.99.%'"
  </code></pre></li>
  </ol>
  
  <p>In my case approaches 1,2 &amp; 4 simply didn't work. The third approach works well and it's really enough. But as far as I understand having multiple VPN connections configured can give an ambiguous result for method 3.</p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Is there a way to be more specific (use combined approach maybe?) with method 3, to be able to check the connection name?</li>
  <li><p>Why didn't methods 1 &amp; 2 work for me? Querying it like this</p>
  
  <pre><code>$adapters = (Get-WmiObject -Query "Select * from Win32_NetworkAdapter")
  foreach($a in $adapters) {
      Write-Host $a.Description
  }
  </code></pre>
  
  <p>gives me a list of adapter names with no mention of 'VPN' in their description:</p>
  
  <pre>
  WAN Miniport (SSTP)
  WAN Miniport (IKEv2)
  WAN Miniport (L2TP)
  WAN Miniport (PPTP)
  and so on...
  </pre></li>
  </ol>