Create a Custom Detection Script for the SonicWall Global VPN Client (PowerShell)


Microsoft Endpoint Manager Configuration Manager (MEMCM / SCCM) and Microsoft Intune use Detection Rules to determine the presence of Applications & Win32 Apps. The detection rules ensure that application installations only begin to run if the application is not already installed on the device. This article will serve as an informative guide and give you a clear understanding of how to create an updated custom detection script for each new version of the SonicWall Global VPN Client using PowerShell.

How to Create a Custom Detection Script for the SonicWall Global VPN Client

SonicWall Global VPN Client (File Detection Method)

## Check for SonicWall Global VPN Client (File Detection Method)
$SonicWallGVCExe = (Get-ChildItem -Path "C:\Program Files\SonicWall\Global VPN Client\SWGVC.exe","C:\Program Files (x86)\SonicWall\Global VPN Client\SWGVC.exe" -ErrorAction SilentlyContinue)
$SonicWallGVCExe.FullName
$SonicWallGVCPath = $($SonicWallGVCExe.FullName).Replace("C:\Program Files\","").Replace("C:\Program Files (x86)\","")
$FileVersion = (Get-Item -Path "$($SonicWallGVCExe.FullName)" -ErrorAction SilentlyContinue).VersionInfo.FileVersion

## Create Text File with SonicWall Global VPN Client File Detection Method
$FilePath = "C:\Windows\Temp\SonicWall_GVC_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([String](Get-Item -Path `"`$Env:ProgramFiles\$SonicWallGVCPath`",`"`${Env:ProgramFiles(x86)}\$SonicWallGVCPath`" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge `"$FileVersion`"){"
Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`""
Add-Content -Path "$FilePath" -Value "}"
Invoke-Item $FilePath

Example:

If([String](Get-Item -Path "$Env:ProgramFiles\SonicWall\Global VPN Client\SWGVC.exe","${Env:ProgramFiles(x86)}\SonicWall\Global VPN Client\SWGVC.exe" -ErrorAction SilentlyContinue).VersionInfo.FileVersion -ge "4.10.7.1424"){
Write-Host "Installed"
}

SonicWall Global VPN Client (Registry Detection Method)

## Check for SonicWall Global VPN Client (Registry Detection Method)
$SonicWallGVC = Get-ChildItem -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ItemProperty | Where-Object {$_.DisplayName -like 'Global VPN Client*' } | Select-Object -Property DisplayName, DisplayVersion, PSChildName
$SonicWallGVC.DisplayVersion
$SonicWallGVC.PSChildName

## Create Text File with SonicWall Global VPN Client Registry Detection Method
$FilePath = "C:\Windows\Temp\SonicWall_GVC_Detection_Method.txt"
New-Item -Path "$FilePath" -Force
Set-Content -Path "$FilePath" -Value "If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$($SonicWallGVC.PSChildName)','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$($SonicWallGVC.PSChildName)' -Name DisplayVersion -ea SilentlyContinue) -ge '$($SonicWallGVC.DisplayVersion)') {"
Add-Content -Path "$FilePath" -Value "Write-Host `"Installed`""
Add-Content -Path "$FilePath" -Value "}"
Invoke-Item $FilePath
  • Click Run Script (F5)
  • A text file will open with the SonicWall Global VPN Client Detection Method script required to detect the current version of the SonicWall Global VPN Client that is installed on the device you are running the script from.

Example:

If([Version](Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{83C9BF15-02E7-4049-9758-EE61175CFB7B}','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{83C9BF15-02E7-4049-9758-EE61175CFB7B}' -Name DisplayVersion -ea SilentlyContinue) -ge '4.10.7') {
Write-Host "Installed"
}

Always make sure to test everything in a development environment prior to implementing anything into production. The information in this article is provided “As Is” without warranty of any kind.

Recent Posts