Intune Device
Intune Device
# CONFIGURATION
# ==========================
$ClientId = '23a9f6584'
$ClientSecret = 'mXm8QK22Wi.L2bRf'
$TenantId = '6fb5baac-4b2c4a47'
$DeviceCategoryId = '2ecb0ccd-01'
# ==========================
# AUTHENTICATION
# ==========================
$body = @{
grant_type = "client_credentials"
client_id = $clientId
client_secret = $clientSecret
scope = "https://graph.microsoft.com/.default"
}
$Headers = @{
Authorization = "Bearer $accessToken"
"Content-Type" = "application/json"
}
# ==========================
# GET DEVICES FROM INTUNE
# ==========================
$AllDevices = @()
$uri = "https://graph.microsoft.com/beta/deviceManagement/managedDevices"
do {
$response = Invoke-RestMethod -Method GET -Uri $uri -Headers $Headers
$AllDevices += $response.value
$uri = $response.'@odata.nextLink'
} while ($uri)
# ==========================
# FILTER FOR WINDOWS + MDM
# ==========================
$WindowsMDMDevices = $AllDevices | Where-Object {
$_.operatingSystem -eq "Windows" -and $_.managementAgent -like "*mdm*"
}
# ==========================
# APPLY DEVICE CATEGORY
# ==========================
foreach ($device in $WindowsMDMDevices) {
try {
$CategoryRef = @{ "@odata.id" =
"https://graph.microsoft.com/beta/deviceManagement/deviceCategories/
$DeviceCategoryId" }
$bodyJson = $CategoryRef | ConvertTo-Json -Depth 2