-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathReportByGroup.ps1
More file actions
57 lines (46 loc) · 2.63 KB
/
ReportByGroup.ps1
File metadata and controls
57 lines (46 loc) · 2.63 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
# Name: ReportByGroup.ps1
# Description: script is designed to generate CSV files that show what data is applicable for each endpoint in a certain group.
# This script as built is designed to work with the Missing Third-Party & Windows Updates and to only Show endpoint name and Update Name - This can be edited below
# 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>'
$csvFileDirectory = "<Insert Directory Here>"
$reportData = Get-Action1 ReportData -Id "<Insert Report ID Here>" #Please create report by cloning report and turning into simple report that sorts by endpoint
# Step 1: Retrieve Endpoint Groups
$endpointGroups = Get-Action1 EndpointGroups
# Step 2: Retrieve all endpoints in each group and store in a hashtable for quick lookup
$groupEndpointsHashtable = @{}
foreach ($group in $endpointGroups) {
$groupEndpoints = Get-Action1 EndpointGroupMembers -ID $group.id
$groupEndpointsHashtable[$group.id] = $groupEndpoints
}
# Step 3 & 4: Filter Report Data for Each Group and Export to CSV
foreach ($group in $endpointGroups) {
# Retrieve endpoints for current group from hashtable
$currentGroupEndpoints = $groupEndpointsHashtable[$group.id]
# Filter report data based on current group endpoints
$filteredReportData = foreach ($data in $reportData) {
$endpointName = $data.fields.'Endpoint Name'
if ($currentGroupEndpoints.name -contains $endpointName) {
# Create custom object for each record that matches the group - Note can be adjusted to show different report fields to work with different reports
[PSCustomObject]@{
EndpointName = $endpointName
UpdateName = $data.fields.'Update Name'
}
}
}
# Export the filtered data to a CSV file
$csvFileName = "$csvFileDirectory\ReportData_Group_" + $group.name + ".csv"
$filteredReportData | Export-Csv -Path $csvFileName -NoTypeInformation
}