PowerShell – Check VPN Connection, Present Splash, Install MSI

email me

Using PowerShell, this performs an upgrade to current VPN software (Pulse, in my case). It detects if user is on VPN, notifies them to disconnect, disconnects from VPN, and then upgrades the VPN software.


$VPNStatus = Get-WmiObject -Query "Select * from Win32_NetworkAdapter where (Name like '%Juniper%') and NetEnabled='True'"

$VPNStatus = [bool]$VPNStatus

$PackagePath = $MyInvocation.MyCommand.Path

$dir = Split-Path $PackagePath

#$dir = "C:\SpecificPath"

$ErrorActionPreference= 'silentlycontinue'

clear-host

if ($VPNStatus) {

# timer for splash
Start-Process "$dir\TimerX.exe"

# kill existing process
Stop-Process -Name "mshta" -Force
Start-Sleep -s 2

# launch splash - wait for user to close splash
Start-Process "$dir\splash.hta" -Wait

# terminate VPN
Stop-Process -Name "Pulse" -Force
Stop-Process -Name "PulseSecureService" -Force

# launch animation
Start-Process "$dir\animation.hta"

# begin install - install with shared install enabled
Start-Process $dir\Install.exe -ArgumentList "/I $dir\setup64.msi /qn"
Start-Sleep -s 10

# wait for install to complete
Get-Process -Name Install -ErrorAction SilentlyContinue | Wait-Process

# helper process populates Pulse app with connections
Start-Process "C:\Program Files (x86)\Pulse Secure\Pulse\PulseHelper.exe"

# kill splash timer
Stop-Process -Name "timer" -Force

[Environment]::Exit(0)

}

else {

# no splash
# begin install - install with shared install enabled
Start-Process $dir\Install.exe -ArgumentList "/I $dir\setup64.msi /qn"

# wait for install to complete
Get-Process -Name Install -ErrorAction SilentlyContinue | Wait-Process

[Environment]::Exit(0)
}

[Environment]::Exit(1)


Notes

Install.exe = msiexec.exe. I copy and use it in the package to differentiate the MSI installer in task manager, and other monitoring utilities. I normally do the same for mshta.exe as well.

For Shared Install, see Pulse Disconnecting Users – Shared Install

 

tags: MrNetTek