-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSCCMSystems_to_Spectre.ps1
More file actions
150 lines (127 loc) · 5.4 KB
/
Copy pathSCCMSystems_to_Spectre.ps1
File metadata and controls
150 lines (127 loc) · 5.4 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<#
# Created By: Tyler.Filkins
# Created Date: 2017-01-25
#
# Description: This script updates the SCCM systems collection file in SpectreSource with new
# data from the SCCM all systems report. It authenticates to the SpectreSource
# API and uploads the data one system at a time (it is not very efficient or
# speedy, but it works).
#
#>
# authenticate to the Spectre API
function authenticate()
{
Write-Host "authenticating to Spectre API..." -ForegroundColor Magenta
add-type -ErrorAction SilentlyContinue @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
# ignore warning about untrusted cert
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy -ErrorAction SilentlyContinue
$body = @{
username = "get_ur_own"
password = "dont_tell_no_one"
}
$resource = "https://*.*.*.*/api/authenticate"
$response = Invoke-RestMethod -Method Post -Uri $resource -Body $body
return $response.token
}
#-------------------------#
# EXECUTION STARTS HERE #
#-------------------------#
$count = 0
$allsystems_report_path = '\\network_or_file\path\to\SCCM\all_systems_report'
$allsystems = Import-Csv $allsystems_report_path
# authenticate and capture JWT token
$token = authenticate
$headers = @{
"Authorization" = "Bearer "+$token
"Content-Type" = "application/json"
}
# clear the collections file in SpectreSource
$resource = "https://*.*.*.*/api/sccm/clear_upload"
Write-Host "clearing SCCM systems collection file..." -ForegroundColor Magenta
$response = Invoke-RestMethod -Method Get -Uri $resource -Headers $headers
if ($response.success)
{
# set resource to upload url
$resource = "https://*.*.*.*/api/sccm/upload"
Write-Host "starting POST loop..." -ForegroundColor Green
# cycle through the systems and create a custom PS object list of the data we care about
foreach($system in $allsystems)
{
$data = @()
$data += [pscustomobject] @{
system_name = $system.SystemName
district = $system.District
region = $system.Region
group = $system.Group
owner = $system.Owner
days_since_last_logon = $system.DaysLastLogon
stale_45days = $system.Stale45Days
client_status = $system.ClientStatus
client_version = $system.ClientVersion
operating_system = $system.OperatingSystem
operating_system_version = $system.OperatingSystemVersion
os_roundup = $system.OSRoundup
os_arch = $system.OSArch
system_role = $system.SystemRole
serial_number = $system.SerialNumber
chassis_type = $system.ChassisType
manufacturer = $system.Manufacturer
model = $system.Model
processor = $system.Processor
image_source = $system.ImageSource
image_date = $system.ImageDate
coe_compliant = $system.COECompliant
ps_version = $system.PowerShellVersion
patch_total = $system.PatchTotal
patch_installed = $system.PatchInstalled
patch_missing = $system.PatchMissing
patch_unknown = $system.PatchUnknown
patch_percent = $system.PatchPercent
scep_installed = $system.SCEPInstalled
cylance_installed = $system.CylanceInstalled
anyconnect_installed = $system.AnyConnectInstalled
anyconnect_websecurity = $system.AnyConnectWebSecurity
bitlocker_status = $system.BitLockerStatus
tpm_enabled = $system.TPM_IsEnabled
tpm_activated = $system.TPM_IsActivated
tpm_owned = $system.TPM_IsOwned
ie_version = $system.IEVersion
ad_location = $system.ADLocation
primary_users = $system.PrimaryUsers
last_logon_username = $system.LastLogonUserName
ad_last_logon = $system.ADLastLogon
ad_password_last_set = $system.ADPasswordLastSet
ad_modified= $system.ADModified
sccm_last_heartbeat = $system.SCCMLastHeartBeat
sccm_management_point = $system.SCCMManagementPoint
sccm_last_health_eval = $system.SCCMLastHealthEval
sccm_last_health_result = $system.SCCMLastHealthResult
report_date = $system.ReportDate
}
# convert it to JSON format
$data_json = ConvertTo-Json $data
# post it
$response = Invoke-RestMethod -Method Post -Uri $resource -Body $data_json -Headers $headers
# output an update
Write-Host "System posted: $($system.SystemName)" -ForegroundColor Yellow
[int]$percentcomplete = ($count++ / $allsystems.count) * 100
Write-Progress -Activity "Enumerating SCCM systems in SpectreSource" -Status "Percent Complete: $percentcomplete %" -PercentComplete $percentcomplete
# chill out for a second
#sleep -s 1
}
Write-Host "* SCCM Systems to Spectre sync completed! *" -ForegroundColor Green
}
else
{
Write-Host "Error: $($response.message)" -ForegroundColor Red
}