SOLVED

Intune Graph API permissions - no Application permissions - why?

%3CLINGO-SUB%20id%3D%22lingo-sub-1453545%22%20slang%3D%22en-US%22%3EIntune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1453545%22%20slang%3D%22en-US%22%3E%3CP%3EI'm%20hoping%20to%20gain%20an%20understanding%20why%20all%20Intune%20Graph%20resources%20and%20actions%20only%20allow%20Delegated%20permissions.%26nbsp%3B%20This%20essentially%20means%20no%20unattended%20administration%20available%2C%20at%20least%20not%20App-only.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can't%20figure%20out%20why%20it%20is%20like%20this.%26nbsp%3B%20The%20Intune%20PowerShell%20SDK%20(i.e.%20Microsoft.Graph.Intune%20PowerShell%20gallery%20module)%20can%20be%20used%20unattended'ly%2C%20but%20the%20sample%20for%20this%20that%20is%20on%20GitHub%20is%20using%20ConvertFrom-SecureString%20%7C%20Out-File.%26nbsp%3B%20That's%20not%20really%20secure%2C%20nor%20is%20sending%20plain%20text%20password%20to%20MS%20Graph.%26nbsp%3B%20So%20Application%20permissions%2C%20enabling%20Certificate%20(or%20Client%20Credential)%20authentication%20would%20be%20far%20superior.%26nbsp%3B%20Reference%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fpowershell-intune-samples%2Ftree%2Fmaster%2FAuthentication%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fmicrosoftgraph%2Fpowershell-intune-samples%2Ftree%2Fmaster%2FAuthentication%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUse%20cases%20that%20I'm%20particularly%20talking%20about%20are%20ones%20like%20resetPasscode%2C%20or%20remoteLock.%26nbsp%3B%20We%20should%20be%20able%20to%20trigger%20these%20actions%20with%20an%20App%20Registration%20that%20has%20Application%20permissions.%26nbsp%3B%20We%20could%20then%20script%20automatic%20reactions%2C%20such%20as%20remoteLock%20upon%20a%20particular%20Azure%20AD%20Sign-In%20event%20or%20risk%20detection.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20somebody%20please%20tell%20me%20why%20Intune's%20Graph%20permissions%20are%20strictly%20only%20Delegated%3F%26nbsp%3B%20This%20same%20issue%20applies%20to%20about%20every%20single%20thing%20an%20Admin%20might%20want%20to%20use%20MS%20Graph%20API's%20for.%26nbsp%3B%20I%20wish%20there%20was%20a%20TON%20of%20focus%20in%20this%20area%20by%20Microsoft.%26nbsp%3B%20If%20magically%20all%20of%20a%20sudden%20customer%20administrative%20automation%20was%20catered%20to%2C%20this%20would%20be%20a%20massive%20positive%20thing%20leading%20to%20mass%20embracement%20from%20customers.%26nbsp%3B%20Right%20now%2C%20it%20sometimes%20seems%20like%20MS%20doesn't%20want%20customers%20automating%20things%20with%20unattended%20intention.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1453545%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EApplication%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDelegated%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EGraph%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EIntune%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPermissions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1453886%22%20slang%3D%22en-US%22%3ERe%3A%20Intune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1453886%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F186539%22%20target%3D%22_blank%22%3E%40Thijs%20Lecomte%3C%2FA%3E%26nbsp%3BThanks%20for%20the%20info%2C%20this%20is%20great.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20wonder%20how%2Fwhen%20this%20will%20factor%20into%20the%20Intune%20PowerShell%20SDK.%26nbsp%3B%20I%20suppose%20they%20Connect-MSGraph%20cmdlet%20from%20the%20module%2FSDK%20will%20just%20need%20to%20get%20some%20client%20credential%20flow%20functionality%20added.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1454255%22%20slang%3D%22en-US%22%3ERe%3A%20Intune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1454255%22%20slang%3D%22en-US%22%3EI%20wouldn't%20get%20your%20hopes%20up%20that%20the%20Powershell%20cmdlets%20will%20support%20application%20permissions%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20Graph%20API%20is%20rather%20easy%20to%20use%20and%20I%20would%20recommend%20looking%20into%20this.%3CBR%20%2F%3EAs%20the%20Graph%20API%20has%20support%20for%20features%20much%20earlier%20than%20the%20Powershell%20SDK%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1454871%22%20slang%3D%22en-US%22%3ERe%3A%20Intune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1454871%22%20slang%3D%22en-US%22%3EGood%20advice%20and%20duly%20noted.%20I've%20got%20a%20mini%20module%20ready%20to%20go%20for%20easy%20app-only%20certificate%20authentication%20to%20Graph%20so%20good%20there.%20Incidentally%2C%20I%20tested%20the%20beta%20remoteLock%2C%20and%20it%20seems%20to%20not%20work.%20Will%20need%20to%20test%20a%20bit%20I%20guess%2C%20or%20wait%20if%20it%20is%20truly%20just%20not%20working%20yet.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1455712%22%20slang%3D%22en-US%22%3ERe%3A%20Intune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1455712%22%20slang%3D%22en-US%22%3EKnow%20that%20beta%20channel%20contain%20some%20bugs%2C%20but%20it%20should%20a%20a%20minimum%3CBR%20%2F%3ELet%20me%20know%20if%20it%20doesn't%20work%2C%20I'll%20try%20to%20test%20as%20well%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1456392%22%20slang%3D%22en-US%22%3ERe%3A%20Intune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1456392%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F186539%22%20target%3D%22_blank%22%3E%40Thijs%20Lecomte%3C%2FA%3E%26nbsp%3BThanks%20very%20much%20for%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FJeremyTBradshaw%2FPowerShell%2Fblob%2Fmaster%2F.Modules%2FmsGraphFunctions.psm1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FJeremyTBradshaw%2FPowerShell%2Fblob%2Fmaster%2F.Modules%2FmsGraphFunctions.psm1%3C%2FA%3E%26nbsp%3B-%20that%20is%20my%20module.%26nbsp%3B%20It%20currently%20is%20setup%20to%20accommodate%20certificate%20authentication%20in%20the%20client%20credential%20flow.%26nbsp%3B%20The%20functions%20are%3A%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-MSGraphAccessToken%0ANew-SelfSignedAzureADRegisteredAppCertificate%0ANew-MSGraphQuery%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20my%20example%20which%20%3CSTRIKE%3Eis%3C%2FSTRIKE%3E%26nbsp%3Bwas%20failing%2C%20%3CSTRIKE%3EI'm%3C%2FSTRIKE%3E%26nbsp%3BI%20was%20getting%20an%20access%20token%20successfully%2C%20and%20then%20with%20New-MSGraphQuery%20%3CSTRIKE%3Ecan%3C%2FSTRIKE%3E%26nbsp%3Bcould%20successfully%20list%20devices%20using%20v1.0%20or%20beta%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%23%20list%20devices%20via%20v1.0%3A%0A%26gt%3B%24q1%20%3D%20New-MSGraphQuery%20-AccessToken%20%24Token%20-API%20v1.0%20-Method%20GET%20-Query%20deviceManagement%2FmanagedDevices%0A%26gt%3B%24q1.value%20%7C%20select%20deviceName%2C%20model%0A%0AdeviceName%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20model%0A----------%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-----%0AHTPC-G1%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Z390%20I%20AORUS%20PRO%20WIFI%0Aj_AndroidForWork_6%2F9%2F2020_10%3A12%20PM%20ONEPLUS%20A5010%0A%0A%23%20list%20devices%20via%20beta%3A%0A%26gt%3B%24q2%20%3D%20New-MSGraphQuery%20-AccessToken%20%24Token%20-API%20beta%20-Method%20GET%20-Query%20deviceManagement%2FmanagedDevices%0A%26gt%3B%24Q2.value%20%7C%20select%20deviceName%2C%20model%0A%0AdeviceName%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20model%0A----------%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-----%0AHTPC-G1%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Z390%20I%20AORUS%20PRO%20WIFI%0Aj_AndroidForWork_6%2F9%2F2020_10%3A12%20PM%20ONEPLUS%20A5010%0A%0A%23%20fail%20to%20remoteLock%20via%20Beta%3A%0A%26gt%3BNew-MSGraphQuery%20-AccessToken%20%24Token%20-API%20beta%20-Method%20POST%20-Query%20deviceManagement%2FmanagedDevices%2F9e250f72-a995-401d-8e32-7edf7fdb2eba%2FremoteLock%0AInvoke-RestMethod%20%3A%20%7B%0A%20%20%22error%22%3A%20%7B%0A%20%20%20%20%22code%22%3A%20%22No%20method%20match%20route%20template%22%2C%0A%20%20%20%20%22message%22%3A%20%22No%20OData%20route%20exists%20that%20match%20template%20~%2Fsingleton%2Fnavigation%2Fkey%2Faction%20with%20http%20verb%20GET%20for%20request%0A%2FDeviceFE%2FStatelessDeviceFEService%2FdeviceManagement%2FmanagedDevices('9e250f72-a995-401d-8e32-7edf7fdb2eba')%2Fmicrosoft.management.services.api.remoteLock.%22%2C%0A%20%20%20%20%22innerError%22%3A%20%7B%0A%20%20%20%20%20%20%22request-id%22%3A%20%2201f99d16-88e2-4b2c-b053-0fbfaec43947%22%2C%0A%20%20%20%20%20%20%22date%22%3A%20%222020-06-11T12%3A39%3A08%22%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0AAt%20C%3A%5CUsers%5C%3CMYPROFILE%3E%5CGitHub%5CPowerShell%5C.Modules%5CmsGraphFunctions.psm1%3A125%20char%3A5%0A%2B%20%20%20%20%20Invoke-RestMethod%20%40QueryProps%20-OutVariable%20QueryResponse%0A%2B%20%20%20%20%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%0A%20%20%20%20%2B%20CategoryInfo%20%20%20%20%20%20%20%20%20%20%3A%20InvalidOperation%3A%20(System.Net.HttpWebRequest%3AHttpWebRequest)%20%5BInvoke-RestMethod%5D%2C%20WebException%0A%20%20%20%20%2B%20FullyQualifiedErrorId%20%3A%20WebCmdletWebResponseException%2CMicrosoft.PowerShell.Commands.InvokeRestMethodCommand%3C%2FMYPROFILE%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUpon%20crafting%20this%20reply%2C%20I%20noticed%20in%20the%20error%20%22No%20OData%20route%20exists%20.......%20with%20http%20verb%20%3CFONT%20color%3D%22%23FF0000%22%3EGET%3C%2FFONT%3E%20for%20request%22.%26nbsp%3B%20This%20made%20me%20realize%20my%20problem.%26nbsp%3B%20I%20had%20hard-coded%20%22Get%22%20as%20the%20method%20in%20my%20New-MSGraphQuery%20function%2C%20where%20I%20should%20have%20set%20it%20to%20my%20parameter%20-Method's%20value%20(%24Method).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOriginal%2C%20non-working%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%20%20%20%20%24QueryProps%20%3D%20%40%7B%0A%0A%20%20%20%20%20%20%20%20Headers%20%20%20%20%20%3D%20%40%7B%20Authorization%20%3D%20%22Bearer%20%24(%24AccessToken.access_token)%22%20%7D%0A%20%20%20%20%20%20%20%20Uri%20%20%20%20%20%20%20%20%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%2F%24(%24API)%2F%24(%24Query)%22%0A%20%20%20%20%20%20%20%20Method%20%20%20%20%20%20%3D%20'Get'%0A%20%20%20%20%20%20%20%20ContentType%20%3D%20'application%2Fjson'%0A%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFixed%2C%20working%20code%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%20%20%20%20%24QueryProps%20%3D%20%40%7B%0A%0A%20%20%20%20%20%20%20%20Headers%20%20%20%20%20%3D%20%40%7B%20Authorization%20%3D%20%22Bearer%20%24(%24AccessToken.access_token)%22%20%7D%0A%20%20%20%20%20%20%20%20Uri%20%20%20%20%20%20%20%20%20%3D%20%22https%3A%2F%2Fgraph.microsoft.com%2F%24(%24API)%2F%24(%24Query)%22%0A%20%20%20%20%20%20%20%20Method%20%20%20%20%20%20%3D%20%24Method%0A%20%20%20%20%20%20%20%20ContentType%20%3D%20'application%2Fjson'%0A%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAgain%2C%20thanks%20very%20much!%26nbsp%3B%20I%20still%20needed%20this%20post%20and%20your%20response%20to%20get%20me%20looking%20at%20the%20Beta%20reference%20instead%20of%20v1.0.%26nbsp%3B%20It%20was%20only%20after%20that%2C%20that%20I%20could%20flush%20out%20this%20error%20in%20my%20script.%26nbsp%3B%20The%20-Method%20parameter%20was%20added%20to%20the%20function%20after%20a%20while%2C%20and%20I%20must%20have%20gotten%20distracted%20in%20the%20process%20and%20forgot%20to%20actually%20incorporate%20the%20parameter%20into%20the%20script%20after%20declaring%20in%20my%20params%20block.%26nbsp%3B%20All%20good%20now%20though!%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1456481%22%20slang%3D%22en-US%22%3ERe%3A%20Intune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1456481%22%20slang%3D%22en-US%22%3EGlad%20that%20worked!%3CBR%20%2F%3EHave%20fun%20automating%20Intune%20%3A)%3C%2Fimg%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1453557%22%20slang%3D%22en-US%22%3ERe%3A%20Intune%20Graph%20API%20permissions%20-%20no%20Application%20permissions%20-%20why%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1453557%22%20slang%3D%22en-US%22%3EApplication%20support%20for%20all%20Intune%20endpoints%20have%20been%20added%2C%20but%20it's%20still%20in%20the%20beta%20Graph%20though%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fresources%2Fintune-device-mgt-conceptual%3Fview%3Dgraph-rest-beta%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fgraph%2Fapi%2Fresources%2Fintune-device-mgt-conceptual%3Fview%3Dgraph-rest-beta%3C%2FA%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I'm hoping to gain an understanding why all Intune Graph resources and actions only allow Delegated permissions.  This essentially means no unattended administration available, at least not App-only.

 

I can't figure out why it is like this.  The Intune PowerShell SDK (i.e. Microsoft.Graph.Intune PowerShell gallery module) can be used unattended'ly, but the sample for this that is on GitHub is using ConvertFrom-SecureString | Out-File.  That's not really secure, nor is sending plain text password to MS Graph (not referring to the sample with the latter comment, rather this: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc).  So Application permissions, enabling Certificate (or Client Credential) authentication would be far superior.

 

Referenced sample script: https://github.com/microsoftgraph/powershell-intune-samples/tree/master/Authentication

 

Use cases that I'm particularly talking about are ones like resetPasscode, or remoteLock.  We should be able to trigger these actions with an App Registration that has Application permissions.  We could then script automatic reactions, such as remoteLock upon a particular Azure AD Sign-In event or risk detection.

 

Can somebody please tell me why Intune's Graph permissions are strictly only Delegated?  This same issue applies to about every single thing an Admin might want to use MS Graph API's for.  I wish there was a TON of focus in this area by Microsoft.  If magically all of a sudden customer administrative automation was catered to, this would be a massive positive thing leading to mass embracement from customers.  Right now, it sometimes seems like MS doesn't want customers automating things with unattended intention.

 

Thanks in advance.

7 Replies
Highlighted
Best Response confirmed by Jeremy Bradshaw (Contributor)
Solution
Application support for all Intune endpoints have been added, but it's still in the beta Graph though
https://docs.microsoft.com/en-us/graph/api/resources/intune-device-mgt-conceptual?view=graph-rest-be...
Highlighted

@Thijs Lecomte Thanks for the info, this is great.

 

I wonder how/when this will factor into the Intune PowerShell SDK.  I suppose they Connect-MSGraph cmdlet from the module/SDK will just need to get some client credential flow functionality added.

Highlighted
I wouldn't get your hopes up that the Powershell cmdlets will support application permissions

The Graph API is rather easy to use and I would recommend looking into this.
As the Graph API has support for features much earlier than the Powershell SDK
Highlighted
Good advice and duly noted. I've got a mini module ready to go for easy app-only certificate authentication to Graph so good there. Incidentally, I tested the beta remoteLock, and it seems to not work. Will need to test a bit I guess, or wait if it is truly just not working yet.
Highlighted
Know that beta channel contain some bugs, but it should a a minimum
Let me know if it doesn't work, I'll try to test as well
Highlighted

@Thijs Lecomte Thanks very much for this.

 

https://github.com/JeremyTBradshaw/PowerShell/blob/master/.Modules/msGraphFunctions.psm1 - that is my module.  It currently is setup to accommodate certificate authentication in the client credential flow.  The functions are: 

 

 

Get-MSGraphAccessToken
New-SelfSignedAzureADRegisteredAppCertificate
New-MSGraphQuery

 

 

 

For my example which is was failing, I'm I was getting an access token successfully, and then with New-MSGraphQuery can could successfully list devices using v1.0 or beta:

 

 

# list devices via v1.0:
>$q1 = New-MSGraphQuery -AccessToken $Token -API v1.0 -Method GET -Query deviceManagement/managedDevices
>$q1.value | select deviceName, model

deviceName                         model
----------                         -----
HTPC-G1                            Z390 I AORUS PRO WIFI
j_AndroidForWork_6/9/2020_10:12 PM ONEPLUS A5010

# list devices via beta:
>$q2 = New-MSGraphQuery -AccessToken $Token -API beta -Method GET -Query deviceManagement/managedDevices
>$Q2.value | select deviceName, model

deviceName                         model
----------                         -----
HTPC-G1                            Z390 I AORUS PRO WIFI
j_AndroidForWork_6/9/2020_10:12 PM ONEPLUS A5010

# fail to remoteLock via Beta:
>New-MSGraphQuery -AccessToken $Token -API beta -Method POST -Query deviceManagement/managedDevices/9e250f72-a995-401d-8e32-7edf7fdb2eba/remoteLock
Invoke-RestMethod : {
  "error": {
    "code": "No method match route template",
    "message": "No OData route exists that match template ~/singleton/navigation/key/action with http verb GET for request
/DeviceFE/StatelessDeviceFEService/deviceManagement/managedDevices('9e250f72-a995-401d-8e32-7edf7fdb2eba')/microsoft.management.services.api.remoteLock.",
    "innerError": {
      "request-id": "01f99d16-88e2-4b2c-b053-0fbfaec43947",
      "date": "2020-06-11T12:39:08"
    }
  }
}
At C:\Users\<myProfile>\GitHub\PowerShell\.Modules\msGraphFunctions.psm1:125 char:5
+     Invoke-RestMethod @QueryProps -OutVariable QueryResponse
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

 

Upon crafting this reply, I noticed in the error "No OData route exists ....... with http verb GET for request".  This made me realize my problem.  I had hard-coded "Get" as the method in my New-MSGraphQuery function, where I should have set it to my parameter -Method's value ($Method).

 

Original, non-working code:

 

    $QueryProps = @{

        Headers     = @{ Authorization = "Bearer $($AccessToken.access_token)" }
        Uri         = "https://graph.microsoft.com/$($API)/$($Query)"
        Method      = 'Get'
        ContentType = 'application/json'
    }

 

 

Fixed, working code:

 

    $QueryProps = @{

        Headers     = @{ Authorization = "Bearer $($AccessToken.access_token)" }
        Uri         = "https://graph.microsoft.com/$($API)/$($Query)"
        Method      = $Method
        ContentType = 'application/json'
    }

 

 

Again, thanks very much!  I still needed this post and your response to get me looking at the Beta reference instead of v1.0.  It was only after that, that I could flush out this error in my script.  The -Method parameter was added to the function after a while, and I must have gotten distracted in the process and forgot to actually incorporate the parameter into the script after declaring in my params block.  All good now though!

 

 

Highlighted
Glad that worked!
Have fun automating Intune :)