-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-GSAClientPolicyRules.ps1
73 lines (72 loc) · 3.03 KB
/
Get-GSAClientPolicyRules.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function Get-GSAClientPolicyRules {
<#
.SYNOPSIS
this cmdlet lists Global Secrure Access client local policies.
.DESCRIPTION
Reads configuration from regisrty in json format, export it as pscustomobject
.EXAMPLE
Get-GSAClientDetails
#>
[CmdletBinding()]
Param (
)
#try read Global Secure Access config from registry
$GSACRegKey = 'HKLM:\SOFTWARE\Microsoft\Global Secure Access Client'
if (!(Test-Path $GSACRegKey)) {
Write-Output "Global Secure Access Client regkey $GSACRegKey not found on this machine"
break
}
$KeyValue = Get-ItemProperty $GSACRegKey
$ForwardingProfile = $KeyValue.ForwardingProfile | ConvertFrom-Json
$channels = $ForwardingProfile.policy.channels
$rules = $ForwardingProfile.policy.rules
$rulesoutput = New-Object -TypeName System.Collections.ArrayList
#$rule = $rules[23]
foreach ($rule in $rules) {
if ($rule.matchingCriteria.address.ips) {
#$ip = $rule.matchingCriteria.address.ips[0]
$channelName = ($channels | Where-Object { $_.id -eq $rule.channelId }).name
foreach ($ip in $rule.matchingCriteria.address.ips) {
$HexStart = [Convert]::ToString($ip.start, 16)
$ipStart = [Convert]::ToUint64($HexStart, 16) -as [ipaddress]
$HexEnd = [Convert]::ToString($ip.start, 16)
$ipEnd = [Convert]::ToUint64($HexEnd, 16) -as [ipaddress]
$ruleEntry = [PSCustomObject]@{
id = $rule.id
channel = $channelName
order = $rule.order
action = $rule.action
hardening = $rule.hardening
ipStart = $ipStart
ipEnd = $ipEnd
fqdn = ''
protocol = $rule.matchingCriteria.protocol
portStart = $rule.matchingCriteria.ports.start
portEnd = $rule.matchingCriteria.ports.end
}
$rulesoutput.Add($ruleEntry) | Out-Null
}
}
if ($rule.matchingCriteria.address.fqdns) {
$fqdn = $rule.matchingCriteria.address.fqdns[0]
foreach ($fqdn in $rule.matchingCriteria.address.fqdns) {
$fqdnformated = $fqdn.replace('\', '')
$ruleEntry = [PSCustomObject]@{
id = $rule.id
channel = $channelName
order = $rule.order
action = $rule.action
hardening = $rule.hardening
ipStart = ''
ipEnd = ''
fqdn = $fqdnformated
protocol = $rule.matchingCriteria.protocol
portStart = $rule.matchingCriteria.ports.start
portEnd = $rule.matchingCriteria.ports.end
}
$rulesoutput.Add($ruleEntry) | Out-Null
}
}
}
$rulesoutput
}