Neossian
Neossian

Reputation: 705

MS Graph API - ManagedDevices obtaining Scope

My goal is to create a schedulable PowerShell script that will report on recently enrolled devices. I have created the Application and granted some permissions.

 $OauthTokenEndpoint = 'https://login.microsoftonline.com/tenantid/oauth2/token'

$OauthRequest = @{
    grant_type="client_credentials"
    client_id = "clientidguid"
    client_secret = "clientidsecret"
    resource = "https://graph.microsoft.com"
    scope="DeviceManagementManagedDevices.Read.All"
}

$AuthResponse = Invoke-RestMethod -Uri $OauthTokenEndpoint -Method Post -ContentType application/x-www-form-urlencoded -Body $OauthRequest
$Token = $authresponse.access_token

#this query completes successfully
$Success = Invoke-restmethod -uri https://graph.microsoft.com/v1.0/users/[email protected]/ownedDevices  -Headers @{Authorization = "Bearer $Token"}  -method Get

#this query fails with 401 unauthorised
$401Error = Invoke-RestMethod -Headers @{Authorization = "Bearer $Token"} -uri  "https://graph.microsoft.com/beta/managedDevices/deviceguid?`$select=hardwareInformation" -Method GET

I believe that my issue is that I have not, or can not grant DeviceManagementManagedDevices.Read.All scope permissions to my application. This API works with Graph Explorer, and I have an interactive version of this script that uses delegated permissions that works. How can I permit my Application to access the ManagedDevices API endpoint so that I can use it non-interactively.

Upvotes: 1

Views: 851

Answers (1)

Neossian
Neossian

Reputation: 705

Received information from Microsoft that using Intune Graph APIs without user credentials is currently not supported.

Upvotes: 1

Related Questions