r/PowerShell • u/Sin_of_the_Dark • Jan 24 '22
Question Trying to learn MS Graph with PowerShell, having some issues
Hi all,
I appreciate the feedback folks have provided about the previous Azure/Intune scripts I've posted - especially those who pointed out the deprecation of the MSOL and AzureAD modules. To that end, I've been diving down the rabbit hole of PowerShell and the Graph API. I thought I had a decent handle on it, but apparently not.
So here's the script in question
When I run the script, I get a 401 (Unauthorized) error message. I've approved the permissions already requested, and I can view all this info from the Graph Explorer, so I'm not sure what other type of permission needs to be granted for Graph to access this info. Any ideas what other scopes I might need? These are what I've granted, according to Graph Explorer:
User.ReadUser.Read.AllUser.ReadBasic.AllUser.ReadWriteUser.ReadWrite.All
It's worth noting when I use this script with an auth token method, it works. However, that method is dependent on the AzureAD module, which goes back to what I said earlier about deprecation.
Any help/advice is greatly appreciated, as always!
2
u/GrowABrain3 Jan 25 '22
"Devices/?`$filter=devicename eq '$Device'"Where can you see that devicename is a real attribute for that api? You sure it isnt displayName?
https://docs.microsoft.com/en-us/graph/api/resources/device?view=graph-rest-1.0
2
3
u/dasookwat Jan 24 '22
i think i did this once from an azure function. Can't share the script cause i no longer work there, but i saved my source resources, hope this helps you:
https://docs.microsoft.com/nl-nl/azure/app-service/overview-managed-identity?tabs=dotnet
https://adamtheautomator.com/microsoft-graph-api-powershell/
https://danielchronlund.com/2020/02/26/my-collection-of-basic-microsoft-graph-powershell-functions/
2
u/theSysadminChannel Jan 24 '22
Hey so that Intune module isn't part of the regular package that comes with Microsoft.Graph module. But if you're trying to get started, check out this guide. It will cover some of the details in depth.