Hello i have created powershell script which get a list of mobileApps. I follow this doc. https://learn.microsoft.com/en-us/graph/api/intune-apps-win32lobapp-list?view=graph-rest-1.0
# Connect to Microsoft Graph API
$appId = ""
$tenantId = ""
$secret = ""
$scopes = "https://graph.microsoft.com/.default"
$token = get-msaltoken -tenantid $tenantId -clientid $appId -clientsecret ( $secret |ConvertTo-SecureString -AsPlainText -Force) -Scopes $scopes
Connect-MgGraph -AccessToken $token.accesstoken
$Headers = @{
"Authorization" = "Bearer $($token.AccessToken)"
"Content-type" = "application/json"
"ExpiresOn" = $token.ExpiresOn
}
$url = "https://graph.microsoft.com/v1/deviceAppManagement/mobileApps"
$response = Invoke-RestMethod -Method GET -Uri $url -Headers $Headers
appId, tenantId and secret are corrent. Also i have given the correct permissions (DeviceManagementApps.Read.All, DeviceManagementApps.ReadWrite.All)
I get the following error.
Welcome To Microsoft Graph!
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:23 char:13
+ $response = Invoke-RestMethod -Method GET -Uri $url -Headers $Headers
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Has anyone the same error?