forked from Action1Corp/APIScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReportByGroup.ps1
More file actions
61 lines (51 loc) · 3.35 KB
/
ReportByGroup.ps1
File metadata and controls
61 lines (51 loc) · 3.35 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
# Name: PSAction1ReportByGroup.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
# Copyright (C) 2024 Action1 Corporation
# 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.
# LIMITATION OF LIABILITY. IN NO EVENT SHALL ACTION1 OR ITS SUPPLIERS, OR THEIR RESPECTIVE
# OFFICERS, DIRECTORS, EMPLOYEES, OR AGENTS BE LIABLE WITH RESPECT TO THE WEBSITE OR
# THE COMPONENTS OR THE SERVICES UNDER ANY CONTRACT, NEGLIGENCE, TORT, STRICT
# LIABILITY OR OTHER LEGAL OR EQUITABLE THEORY (I)FOR ANY AMOUNT IN THE AGGREGATE IN
# EXCESS OF THE GREATER OF FEES PAID BY YOU THEREFOR OR $100; (II) FOR ANY INDIRECT,
# INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES OF ANY KIND WHATSOEVER; (III) FOR
# DATA LOSS OR COST OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; OR (IV) FOR ANY
# MATTER BEYOND ACTION1’S REASONABLE CONTROL. SOME STATES DO NOT ALLOW THE
# EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE ABOVE
# LIMITATIONS AND EXCLUSIONS MAY NOT APPLY TO YOU.
# PSAction1 PowerShell Script for Group Report Analysis
# 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
}