-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriggerMassScan.ps1
62 lines (47 loc) · 1.73 KB
/
triggerMassScan.ps1
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
// This is not working as of 3/10/23
#enter your Client ID from Central
$clientid = "<###>"
#enter your Client Secret from Central
$clientsecret = "<###>"
#uri to authenticate with Central
$authuri = "https://id.sophos.com/api/v2/oauth2/token"
#uri to get tenant ID
$whoami_uri = "https://api.central.sophos.com/whoami/v1"
#this is the full body of the authentication request
$authbod = @{
"grant_type" = 'client_credentials'
"scope" = 'token'
"client_id" = $clientid
"client_secret" = $clientsecret
}
#this will send your bearer token request
$auth = Invoke-RestMethod -uri $authuri -Method Post -Body $authbod -ContentType application/x-www-form-urlencoded
#this will extract your bearer token for later use
$bearer = $auth.access_token
#this stores the token in a readable variable
$headers = @{Authorization="Bearer $bearer"}
#this will send your whoami request for tenant identification
$whoami = Invoke-RestMethod -uri $whoami_uri -Method Get -Headers $headers
#this formats your tenant ID for later use
$tenantID = $whoami.id
#uri to list out machines
$deviceList = $whoami.apiHosts.dataRegion + "/endpoint/v1/endpoints"
#this sends a request to return all endpoints
$getDeviceList = Invoke-RestMethod -uri $deviceList -Headers $header
#this converts your device list into a readable list
$convertGetDeviceList = $getDeviceList.items | Select-Object -Property id
#uri to trigger scan
$scanURL = $whoami.apiHosts.dataRegion + "/endpoint/v1/endpoints/" + $endpointID + "/scans"
#trigger the scan
ForEach ($endpointID in $convertGetDeviceList)
{
$jsonauthbod = $authbod | ConvertTo-Json
$param = @{
Method = "Post"
ContentType = "application/json"
Uri = $scanURL
Body = {}
Headers = $headers
}
Invoke-RestMethod @param
}