Skip to content

Commit e96b738

Browse files
committed
Corrected some cosmetic errors and exit codes
1 parent 5bf11d9 commit e96b738

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

CENTRAL_API_Grab_Endpoint_Status.ps1

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ function Split-StringAfterEqualSign {
2424
}
2525
catch {
2626
Write-Error "An error occurred: $_"
27+
{break}
2728
}
2829
}
2930
Clear-Host
3031
try {
3132
if (($null -eq $ParamClientId) -or ($ParamClientId -eq "")) {
3233
Write-Output "No Client Id provided"
33-
{break}
34+
exit 1
3435
}
3536
if (($null -eq $ParamClientSecret) -or ($ParamClientSecret -eq "")){
3637
Write-Output "No Client Secret provided"
37-
{break}
38+
exit 2
3839
}
3940
else {
4041
$resultClient = Split-StringAfterEqualSign -inputString $ParamClientId
@@ -48,19 +49,17 @@ try {
4849
}
4950
} catch {
5051
Write-Error "A basic error occurred: $_"
51-
exit 1
52+
exit 3
5253
}
5354

5455
Write-Output "==============================================================================="
5556
Write-Output " Sophos CENTRAL API - Endpoints details and Status"
5657
Write-Output "==============================================================================="
57-
#Date Management for variable
5858

5959
#CSV filename and full directory
6060
$ScriptLaunchDate= Get-Date -Format "yyyyMMddHHmmssfff"
6161
$OutputFile = "Endpoints_list_$ScriptLaunchDate.json"
6262

63-
6463
# SOPHOS OAuth URL
6564
$AuthURI = "https://id.sophos.com/api/v2/oauth2/token"
6665

@@ -81,18 +80,14 @@ $AuthHead.Add("content-type", "application/x-www-form-urlencoded")
8180
# Post Request to SOPHOS for OAuth2 token
8281
try {
8382
$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-
}
8883
} catch {
8984
# If there's an error requesting the token, say so, display the error, and break:
9085
Write-Output ""
9186
Write-Output "AUTHENTICATION FAILED - Unable to retreive SOPHOS API Authentication Token"
9287
Write-Output "Please verify the credentials used!"
9388
Write-Output ""
9489
Read-Host -Prompt "Press ENTER to continue..."
95-
exit 2
90+
exit 4
9691
}
9792

9893
# Set the Token for use later on:
@@ -112,7 +107,7 @@ $Result = (Invoke-RestMethod -Method Get -Uri $WhoamiURI -Headers $WhoamiHead -E
112107
# Check if we are using tenant (Central Admin) credentials
113108
if ($Result.idType -ne "tenant") {
114109
Write-Output "Aborting script - idType does not match tenant!"
115-
Break
110+
exit 5
116111
}
117112

118113
# Save Response details
@@ -140,6 +135,7 @@ foreach ($Node in $EndpointList) {
140135
id = $Node.id
141136
type = $Node.type
142137
hostname = $Node.hostname
138+
Group = $Node.group
143139
HealthStatus = $Node.health.overall
144140
HealthThreats = $Node.health.threats
145141
HealthServices = $Node.health.services

0 commit comments

Comments
 (0)