-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevicereport.ps1
More file actions
69 lines (55 loc) · 2.12 KB
/
Copy pathdevicereport.ps1
File metadata and controls
69 lines (55 loc) · 2.12 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
param(
[Parameter(Mandatory)]
[string]$OktaDomain, # e.g. https://your-org.okta.com
[Parameter(Mandatory)]
[string]$ApiToken, # API token
[string]$CsvPath = ".\devices.csv"
)
$headers = @{
"Authorization" = "SSWS $ApiToken"
"Accept" = "application/json"
}
$uri = "$OktaDomain/api/v1/devices?expand=userSummary"
$allDevices = @()
do {
$webResponse = Invoke-WebRequest -Uri $uri -Headers $headers -Method Get
$response = $webResponse.Content | ConvertFrom-Json
# Always treat as array
if ($response -isnot [System.Collections.IEnumerable] -or $response -is [string]) {
$response = @($response)
}
$allDevices += $response
# Pagination (via Link header)
$nextLink = $null
if ($webResponse.Headers.Link) {
$matches = [regex]::Matches($webResponse.Headers.Link, '<([^>]+)>;\s*rel="next"')
if ($matches.Count -gt 0) {
$nextLink = $matches[0].Groups[1].Value
}
}
$uri = $nextLink
} while ($uri)
$results = @()
foreach ($device in $allDevices) {
$profile = $device.profile
$users = $device._embedded.users
$userCount = if ($users) { $users.Count } else { 0 }
$hasMultipleUsers = if ($userCount -gt 1) { "True" } else { "False" }
$userEmails = if ($users) { ($users | ForEach-Object { $_.user.profile.email }) -join ";" } else { "" }
$results += [PSCustomObject]@{
"Device Id" = $device.id
"Display Name" = $profile.displayName
"Platform" = $profile.platform
"Manufacturer" = $profile.manufacturer
"Model" = $profile.model
"OS Version" = $profile.osVersion
"Registered" = $profile.registered
"Disk Encryption Type" = $profile.diskEncryptionType
"Secure Hardware" = $profile.secureHardwarePresent
"User Count" = $userCount
"Has Multiple Users" = $hasMultipleUsers
"User Emails" = $userEmails
}
}
$results | Export-Csv -Path $CsvPath -NoTypeInformation
Write-Host "Done. Exported $($results.Count) devices to $CsvPath"