-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEndpointGroupAutomationComparisonCSV.ps1
More file actions
98 lines (75 loc) · 3.42 KB
/
EndpointGroupAutomationComparisonCSV.ps1
File metadata and controls
98 lines (75 loc) · 3.42 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Name: EndpointGroupAutomationComparisonCSV.ps1
# Description: script is designed to generate CSV that shows what endpoints and groups are assigned to automations
# Documentation: https://github.com/Action1Corp/PSAction1/
# Use Action1 Roadmap system (https://roadmap.action1.com/) to submit feedback or enhancement requests.
# WARNING: Carefully study the provided scripts and components before using them. Test in your non-production lab first.
# Action1 Public Repository Material
# Subject to TERMS_OF_USE.md
# Provided AS IS
# Use at your own risk
# Review and test before production deployment
# © Action1 Corporation
# Comment out below import/set-action1credentials if not needed, or preformed prior
Install-Module -Name PSAction1
Set-Action1Credentials -APIKey '<your api key>' -Secret '<your secret>'
Set-Action1DefaultOrg -Org_ID '<your org id>'
Set-Action1Region -Region '<Enter Region Here>'
$GroupExportpath = "<InsertFilePathHere.csv>"
$EndpointExportpath = "<InsertFilePathHere.csv>"
# Initialize hashtables to store the mappings
$groupPolicyMapping = @()
$endpointPolicyMapping = @()
# Fetch All Groups with Paging
$allGroups = Get-Action1 -Query EndpointGroups
# Fetch All Endpoints with Paging
$allEndpoints = Get-Action1 -Query Endpoints
# Fetch All Policies\Automations with Paging
$allPolicies = Get-Action1 -Query Automations
# Create lookup tables for group and endpoint names by their IDs
$groupNames = @{}
$allGroups | ForEach-Object { $groupNames[$_.id] = $_.name }
$endpointNames = @{}
$allEndpoints | ForEach-Object { $endpointNames[$_.id] = $_.name }
# Iterate through all groups and find their corresponding policies\automations
foreach ($group in $allGroups) {
$policiesForGroup = @()
foreach ($policy in $allPolicies) {
$policyEndpoints = $policy.endpoints | Select-Object -ExpandProperty id
if ($policyEndpoints -contains $group.id) {
$policiesForGroup += $policy.name
}
}
$groupPolicyMapping += [PSCustomObject]@{
GroupName = $group.name
Policies = if ($policiesForGroup) { $policiesForGroup -join ', ' } else { 'none' }
}
}
# Handle the "ALL" case for groups
$policiesForAllGroups = @()
foreach ($policy in $allPolicies) {
$policyEndpoints = $policy.endpoints | Select-Object -ExpandProperty id
if ($policyEndpoints -contains "ALL") {
$policiesForAllGroups += $policy.name
}
}
$groupPolicyMapping += [PSCustomObject]@{
GroupName = "ALL"
Policies = if ($policiesForAllGroups) { $policiesForAllGroups -join ', ' } else { 'none' }
}
# Iterate through all endpoints and find their corresponding policies\automations
foreach ($endpoint in $allEndpoints) {
$policiesForEndpoint = @()
foreach ($policy in $allPolicies) {
$policyEndpoints = $policy.endpoints | Select-Object -ExpandProperty id
if ($policyEndpoints -contains $endpoint.id) {
$policiesForEndpoint += $policy.name
}
}
$endpointPolicyMapping += [PSCustomObject]@{
EndpointName = $endpoint.name
Policies = if ($policiesForEndpoint) { $policiesForEndpoint -join ', ' } else { 'none' }
}
}
# Export the results to two CSV files
$groupPolicyMapping | Export-Csv -Path $GroupExportpath -NoTypeInformation -Encoding UTF8
$endpointPolicyMapping | Export-Csv -Path $EndpointExportpath -NoTypeInformation -Encoding UTF8