Aug 02 2021 01:14 PM - edited Aug 02 2021 01:17 PM
Let me preface this question by stating I may be misunderstanding how this is supposed to work. I'm writing a PowerShell script and need to be able to connect to MS Graph to use Intune Graph. I'm running the following:
$authparams = @{
ClientId = 'appID'
TenantId = 'tenantID'
ClientSecret = ('appSecret' | ConvertTo-SecureString -AsPlainText -Force)
}
$token = Get-MsalToken @authparams
$authorizationHeader = @{
Authorization = $token.CreateAuthorizationHeader()
}
$requestURL = "https://graph.microsoft.com/beta/deviceManagement/managedDevices"
Invoke-RestMethod -Uri $requestURL -Headers $authorizationHeader
Which comes back successful, but when I run a cmd, for example Get-IntuneMangedDevice , it returns
Get-IntuneManagedDevice : Not authenticated. Please use the "Connect-MSGraph" command to authenticate.
At line:1 char:1
+ Get-IntuneManagedDevice
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : AuthenticationError: (:) [Get-DeviceManagement_ManagedDevices], InvalidOperationException
+ FullyQualifiedErrorId : PowerShellGraphSDK_NotAuthenticated,Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.Get_DeviceManagement_ManagedDevices
Aug 02 2021 11:43 PM