@@ -24,17 +24,18 @@ function Split-StringAfterEqualSign {
24
24
}
25
25
catch {
26
26
Write-Error " An error occurred: $_ "
27
+ {break }
27
28
}
28
29
}
29
30
Clear-Host
30
31
try {
31
32
if (($null -eq $ParamClientId ) -or ($ParamClientId -eq " " )) {
32
33
Write-Output " No Client Id provided"
33
- { break }
34
+ exit 1
34
35
}
35
36
if (($null -eq $ParamClientSecret ) -or ($ParamClientSecret -eq " " )){
36
37
Write-Output " No Client Secret provided"
37
- { break }
38
+ exit 2
38
39
}
39
40
else {
40
41
$resultClient = Split-StringAfterEqualSign - inputString $ParamClientId
@@ -48,19 +49,17 @@ try {
48
49
}
49
50
} catch {
50
51
Write-Error " A basic error occurred: $_ "
51
- exit 1
52
+ exit 3
52
53
}
53
54
54
55
Write-Output " ==============================================================================="
55
56
Write-Output " Sophos CENTRAL API - Endpoints details and Status"
56
57
Write-Output " ==============================================================================="
57
- # Date Management for variable
58
58
59
59
# CSV filename and full directory
60
60
$ScriptLaunchDate = Get-Date - Format " yyyyMMddHHmmssfff"
61
61
$OutputFile = " Endpoints_list_$ScriptLaunchDate .json"
62
62
63
-
64
63
# SOPHOS OAuth URL
65
64
$AuthURI = " https://id.sophos.com/api/v2/oauth2/token"
66
65
@@ -81,18 +80,14 @@ $AuthHead.Add("content-type", "application/x-www-form-urlencoded")
81
80
# Post Request to SOPHOS for OAuth2 token
82
81
try {
83
82
$Result = (Invoke-RestMethod - Method Post - Uri $AuthURI - Body $AuthBody - Headers $AuthHead - ErrorAction SilentlyContinue - ErrorVariable ScriptError)
84
- if ($SaveCredentials ) {
85
- $ClientSecret = $ClientSecret | ConvertFrom-SecureString
86
- ConvertTo-Json $ClientID , $ClientSecret | Out-File $CredentialFile - Force
87
- }
88
83
} catch {
89
84
# If there's an error requesting the token, say so, display the error, and break:
90
85
Write-Output " "
91
86
Write-Output " AUTHENTICATION FAILED - Unable to retreive SOPHOS API Authentication Token"
92
87
Write-Output " Please verify the credentials used!"
93
88
Write-Output " "
94
89
Read-Host - Prompt " Press ENTER to continue..."
95
- exit 2
90
+ exit 4
96
91
}
97
92
98
93
# Set the Token for use later on:
@@ -112,7 +107,7 @@ $Result = (Invoke-RestMethod -Method Get -Uri $WhoamiURI -Headers $WhoamiHead -E
112
107
# Check if we are using tenant (Central Admin) credentials
113
108
if ($Result.idType -ne " tenant" ) {
114
109
Write-Output " Aborting script - idType does not match tenant!"
115
- Break
110
+ exit 5
116
111
}
117
112
118
113
# Save Response details
@@ -140,6 +135,7 @@ foreach ($Node in $EndpointList) {
140
135
id = $Node.id
141
136
type = $Node.type
142
137
hostname = $Node.hostname
138
+ Group = $Node.group
143
139
HealthStatus = $Node.health.overall
144
140
HealthThreats = $Node.health.threats
145
141
HealthServices = $Node.health.services
0 commit comments