Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pulse_secure_update
#Script for updating Pulse Secure network connection profiles on Windows clients.
#Any active profiles will be wiped during script execution and replaced with the target configuration.
#The script will also check for active VPN connections and copy the pulse configuration locally before proceeding.
#Make sure to update $connection_profile to match your environment location.
#Pulse 5.3 and above is required for connection delete support.
#Nick Shores - 12/11/18
$connection_profile = '\\wra-fileserver.wra.local\Fileserver\Support\wra.pulsepreconfig'
write-host "Configuration Location:" `n$connection_profile `n
if (test-path $connection_profile){
write-host "Config Found on network path!"
}
else{
write-host "Config not found!"
break
}
#Check VPN connection
$vpnstatus = Get-NetAdapter -IncludeHidden | ? {$_.InterfaceDescription -like "Juniper Networks Virtual Adapter"}
if ($vpnstatus.status -match "Up"){
write-host "VPN Connection Active -- Copying configuration locally"
Copy-Item $connection_profile -Destination C:\temp\wra.pulsepreconfig
$vpnactive = $true
}
#Generate array of strings from local file
if (test-path 'C:\ProgramData\Pulse Secure\ConnectionStore\connstore.dat'){
write-host "Config found at Programdata"
$content = Get-Content "C:\ProgramData\Pulse Secure\ConnectionStore\connstore.dat"
}
if (test-path 'c:\Program Files (x86)\Common Files\Juniper Networks\ConnectionStore\connstore.dat'){
write-host "Config found at Program Files"
$content = Get-Content "c:\Program Files (x86)\Common Files\Juniper Networks\ConnectionStore\connstore.dat"
}
#Filter array of strings for matches
$matches = $content -match "friendly"
#Close pulse secure
write-host "Stopping Pulse Secure"
$exearg = "/stop"
if (test-path 'C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\jamCommand.exe') {
Start-Process "C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\jamCommand.exe" -ArgumentList $exearg
}
if (test-path 'C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\jamCommand.exe') {
Start-Process "C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\jamCommand.exe" -ArgumentList $exearg
}
#Trim list
foreach ($i in $matches){
$s = $i.Split('""')[1]
#Remove profiles
write-host "Removing $s Profile from Pulse Secure"
$exearg = "/deleteconnection ""$s"""
if (test-path 'C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\jamCommand.exe') {
Start-Process "C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\jamCommand.exe" -ArgumentList $exearg
}
if (test-path 'C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\jamCommand.exe') {
Start-Process "C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\jamCommand.exe" -ArgumentList $exearg
}
}
write-host "Importing profile"
if ($vpnactive){$connection_profile = 'C:\temp\wra.pulsepreconfig'}
$exearg = "/importfile $connection_profile"
if (test-path 'C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\jamCommand.exe') {
Start-Process "C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\jamCommand.exe" -ArgumentList $exearg
}
if (test-path 'C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\jamCommand.exe') {
Start-Process "C:\Program Files (x86)\Common Files\Juniper Networks\JamUI\jamCommand.exe" -ArgumentList $exearg
}
if ($vpnactive){
write-host "Cleaning local files"
remove-item $connection_profile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.