Palo Alto Networks Global Protect check Script

I had a customer that wanted to make sure that the Global Protect Client was installed on every windows machine on their domain. To fill this need I created a Power Shell script that scans a list of ip subnets from a text file determines what hosts are up and then checks these hosts for a Global Protect installation by looking for a specific file.

Keep in mind I am not a Power Shell guru (lots of google searching when creating this) so I am sure there are many enhancements that can be made such as multi thread and the like. At any rate hopefully someone else can make use of this. Use at your own risk.

 

#
# 2015-04-06 GP-scan.ps1
# disclaimer I am not a powershell expert just hacked this together to meet the need.
# Script Created by Brian Hitchcock to scan defined network ranges for live hosts then check for GLobal Protect install files.
#
# Script will need to be ran by a user that has permissions to the end machines file system to verify the file is in place.
#
# c:\script\networks.txt File containing /24 networks to check in format 192.168.0 no ending . not extra spaces
# 192.168.0
# 10.10.0.
# c:\script\ips.txt File that is created from ping scan for live hosts. File is over written at each script run

function check-remotefile {

PROCESS {
$file = “\\$_\c$\Program Files\Palo Alto Networks\GlobalProtect\pinfo.dat”
if (test-path $file)
{
write-host “GP installed ” -nonewline
echo $_
}
else
{
write-host “!GP not installed ” -nonewline
echo $_
}
}
}

# Create ips.txt file
echo ” GP-scan by Brian Hitchcock”
echo “Scanning for hosts”
echo ” ” | Out-File c:\script\ips.txt

# loop through networks.txt file do ping scans and write live hosts to ips.txt file
foreach ($network in Get-Content c:\script\networks.txt) {
1..254 | foreach-object { (new-object System.Net.Networkinformation.Ping).Send(“$network.$_”) } | where-object {$_.Status -eq “success”} | select Address | format-table Address -autosize -hidetableheaders | Out-File c:\script\ips.txt -Append
}

# remove blank lines from ips.txt
( Get-Content c:\script\ips.txt ) | Where { $_.Trim(” `t”) } | Set-Content c:\script\ips.txt

echo “Check live hosts for Global Protect”
# check host for Global Protect file
Get-Content c:\script\ips.txt | check-remotefile

 

#####################
Sample run
######################

PS C:\script> .\gp-scan.ps1
GP-scan by Brian Hitchcock
Scanning for hosts
Check live hosts for Global Protect
!GP not installed 192.168.18.1
!GP not installed 192.168.18.2
!GP not installed 192.168.18.3
!GP not installed 192.168.18.4
GP installed 192.168.18.5
!GP not installed 192.168.18.10
!GP not installed 192.168.18.130
!GP not installed 192.168.18.251
!GP not installed 192.168.18.252
!GP not installed 10.20.10.7
!GP not installed 10.20.10.8
!GP not installed 10.20.10.9
!GP not installed 10.20.10.12
!GP not installed 10.20.10.13
!GP not installed 10.20.10.14
!GP not installed 10.20.10.16

 

Leave a Reply