-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-DeviceHardwareInformation.ps1
More file actions
75 lines (64 loc) · 2.79 KB
/
Copy pathGet-DeviceHardwareInformation.ps1
File metadata and controls
75 lines (64 loc) · 2.79 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
# Script to gather Device information, specifically osBuildVersion.
# Cobbled together by James Vincent in September 2023
# Thanks to;
# Tom Machado
#Connect to Graph
$connectionDetails = @{
'ClientId' = 'd1ddf0e4-d672-4dae-b554-9d5bdfd93547'
'RedirectUri' = 'urn:ietf:wg:oauth:2.0:oob'
'Interactive' = $true
}
$authResult = Get-MsalToken @connectionDetails
$authHeaders = @{
'Content-Type'='application/json'
'Authorization'="Bearer " + $authResult.AccessToken
'ExpiresOn'=$authResult.ExpiresOn
}
#Return All Managed Devices
$baseUri = "https://graph.microsoft.com/beta/deviceManagement"
$restParam = @{
Method = 'Get'
Uri = "$baseUri/manageddevices"
Headers = $authHeaders
ContentType = 'Application/json'
}
$managedDevices = Invoke-RestMethod @restParam
$managedDevicesArray = $managedDevices.value
$NextLink = $managedDevices."@odata.nextLink"
while ($null -ne $NextLink){
$managedDevices = (Invoke-RestMethod -Uri $NextLink -Headers $authHeaders -Method Get)
$NextLink = $managedDevices."@odata.nextLink"
$managedDevicesArray += $managedDevices.value
}
#Filter by Android
$managedDeviceList = $managedDevicesArray | Where-object operatingSystem -eq Android
#For each device, pull back the relevant details
foreach ($i in $managedDeviceList) {
$DeviceID = $i.id
$URI = "https://graph.microsoft.com/beta/deviceManagement/manageddevices/$DeviceID"
$Filter = '?$select=deviceName,deviceType,userPrincipalName,userDisplayName,osVersion,operatingSystem,hardwareInformation'
$Request = Invoke-MgGraphRequest -URI $URI$Filter -method GET
$Output = @()
#Gather relevant device details
$DeviceName = $Request.deviceName
$DeviceType = $Request.deviceType
$User = $Request.userPrincipalName
$UserDisplay = $Request.userDisplayName
$Serial = $Request.hardwareInformation.serialNumber
$osName = $Request.operatingSystem
$osVersion = $Request.osVersion
$osBuild = $Request.hardwareInformation.osBuildNumber
#Store the information from this foreach loop into an array
$Output = New-Object -TypeName PSObject -Property @{
"Device Name" = $DeviceName
"Device Type" = $DeviceType
UPN = $User
"User DisplayName" = $UserDisplay
Serial = $Serial
"Operating System" = $osName
"OS Version" = $osVersion
"OS Build" = $osBuild
} | Select-Object "Device Name","UPN","User DisplayName","Device Type",Serial,"Operating System", "OS Version","OS Build"
#Output the array to the CSV File
$Output | Export-Csv C:\Temp\DeviceDetails.csv -Append
}