I used to use scripts from the microsoft graph powershell intune samples, but getting a list of all intune managed devices took a long time and automation was a pain in the (you know what). That was, until I started using the Microsoft.Graph.Intune module.
Though, once your organisation goes over 1000 devices, you might get some results that make you wonder. If you run this command
Get-IntuneManagedDevice
You might get the above result. You can get a result of the devices by changing the command to this:
(Get-IntuneManagedDevice).Value
But that will only get you the result of the 1000 devices. If you want to get a list of all your devices, you better run this command:
Get-IntuneManagedDevice | Get-MSGraphAllPages
Once you get the list of all your devices, you can filter on all the properties of the objects returned:
So if you want to get a list of all Windows devices, you can run:
Get-IntuneManagedDevice -filter "operatingSystem eq 'Windows'" | Get-MSGraphAllPages
This time there is no complete script to download, as the commands are all in this blog post. Have fun scripting!
If you like this blog post and want to support me so I can create and share more scripts, please consider donating to me through PayPal.
Nice blog, thanks for the info
LikeLike
Agree with Rob, rally informative
LikeLike
Get-IntuneManagedDevice -filter “operatingSystem eq ‘Windows’” is Faster !
LikeLike
Thank you for your reply. I will update the post accordingly.
LikeLike
hi, do you know why it does not work for ethernet mac addresses ? Any ideas how to find the device based on mac address ? Get-IntuneManagedDevice -Filter “ethernetMacAddress -like ‘enteryourmac’” | Get-MSGraphallpages
LikeLike
According to this MS site: https://learn.microsoft.com/en-us/graph/api/intune-devices-manageddevice-update?view=graph-rest-1.0
ethernetMacAddress: Indicates Ethernet MAC Address of the device. Default, is Null (Non-Default property) for this property when returned as part of managedDevice entity. Individual get call with select query options is needed to retrieve actual values. Example: deviceManagement/managedDevices({managedDeviceId})?$select=ethernetMacAddress Supports: $select. $Search is not supported.
So I assume that there lies your problem. It won’t give the actual address, when doing a bulk request for all devices, but will return the value null. If you want another value then null, then you need to individually query each device and request their mac address. But if you have many devices this won’t be a fun operation. Back when I wrote this script, we only had 1500 devices and querying them all individually took many hours (because there needs to be a delay in there, otherwise the API will stop responding).
LikeLike
Is there any way to JSON format the output?
LikeLike
Yeah, just add “| ConvertTo-Json” to the end of the line (without the quotes)
LikeLike
I think it’s likely that the server is currently overloaded. My query should come back with about 420,000 machines, and now it’s doing it even to txt output. I suspect memory limitations might be hurting me.
LikeLike
Throws a nasty Gateway Timeout every time I add | ConvertTo-Json.
LikeLike
In that case, first put it in a variable and then output the variable with the | ConvertTo-Json pipe.
LikeLike