This project is read-only.

VPN session detection logic

Topics: Archive - General
Jul 2, 2014 at 3:19 PM
Hello All,

I just started to work with PS App Deployment Toolkit and this tool is awesome! I am no PowerShell expert but thus far its pretty easy to pick up and use for my needs.

With that being said I could use some guidance on how to best handle the logic for a script I am working on. Brief synopsis of what I what I want my script to perform -

" I am deploying an updated WiFi driver via an application using SCCM 2012. I have modified the Deploy-Application script to -CloseApps for "vpnagent" and "vpnui" since I want to prevent this application from deploying to a customer while they have a VPN session established."

Unfortunately these processes are always running on our workstations, even when a VPN session is not established. We are using Cisco AnyConnect Secure Mobility Client. The script actually works as intended but I would like to find a better way to handle the detection of a VPN session being established. Being that these processes are always running if I deploy as is customers in the Office will get a notification to close the VPN processes I have defined.

I appreciate your time and any suggestions.
Jul 2, 2014 at 3:33 PM
This should hopefully work:
# Determine if the Cisco VPN adapter is active with an IP address
$lanAdapters = Get-WmiObject  Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -ErrorAction SilentlyContinue
Foreach ($adapter in $lanAdapters) {
    If ($adapter.Description -match "Cisco Systems VPN Adapter") {
        $vpnConnection = $true
        Break
    }
}

# Only show Welcome Screen over VPN, otherwise silently terminate the VPN processes
If {$vpnConnection -eq $true) {
    Show-InstallationWelcome -CloseApps "vpnagent,vpnui"
}
Else {
    Show-InstallationWelcome -CloseApps "vpnagent,vpnui" -Silent
}
Hope this helps., Dan.
Jul 2, 2014 at 5:34 PM
Thanks for your prompt response Dan, I had to edit the code just a bit but overall is Detecting things successfully.

Just in case anyone else ever needs this please see code below. I am sharing this site with all my friends!
# Determine if the Cisco VPN adapter is active with an IP address
$lanAdapters = Get-WmiObject  Win32_NetworkAdapterConfiguration -Filter "IPEnabled = 'True'" -ErrorAction SilentlyContinue
Foreach ($adapter in $lanAdapters) {
    If ($adapter.Description -match "Cisco AnyConnect Secure Mobility Client Virtual Miniport Adapter for Windows x64") {
        $vpnConnection = $true
        Break
    }
}

# Only show Welcome Screen over VPN, otherwise silently terminate the VPN processes
If ($vpnConnection -eq $true) {
    Show-InstallationWelcome -CloseApps "vpnagent,vpnui" -AllowDefer -DeferTimes 3
}
Else {
    Show-InstallationWelcome -CloseApps "vpnagent,vpnui" -Silent
}
Jul 11, 2014 at 6:48 AM
Some more examples found here if anyone needs to detect VPN connections:
http://csi-windows.com/blog/all/74-powershell/422-powershell-detecting-network-and-vpn-connections-