How to filter Graph API results from 'windowsAutopilotDeviceIdentities' on serial number when the serial number contains spaces?

Mitchell Richters 1 Reputation point
2022-02-20T01:30:38.25+00:00

I'm currently able to filter devices by serial by using a query like https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities?$filter=contains(serialnumber,'AABBCCDD') without any issue, but if the serial contains spaces, I only get a 400 Bad Request.

Examples of how I've tried filtering are:

$filter=contains(serialnumber,'AA BB CC DD')
$filter=contains(serialnumber,'AA%20BB%20CC%20DD')

Unfortunately I have a genuine need to be able to filter on devices by serial where there could be spaces as I have some generic hardware where the serial is 'To be filled by O.E.M', as well as some VMware devices.

Is there a way to achieve what I'm after without fetching all records and filtering after the fact?

Windows Autopilot
Windows Autopilot
A collection of Microsoft technologies used to set up and pre-configure new devices and to reset, repurpose, and recover devices.
407 questions
Microsoft Intune Enrollment
Microsoft Intune Enrollment
Microsoft Intune: A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.Enrollment: The process of requesting, receiving, and installing a certificate.
1,244 questions
Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,331 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Mitchell Richters 1 Reputation point
    2022-02-28T00:55:03.793+00:00

    Sadly, this is apparently by design...

    Hi Mitch,

    >

    Hope you are doing well.

    >

    I would like to provide an update on the case. I had a discussion internally with my Escalation and it is confirmed that the issue is by design. Please let me know if we can have a quick call on Monday to discuss on the next steps on this case.

    >

    I'll look forward to hearing from you.

    >

    Regards,

    Microsoft Representative
    Developer Support Engineer

    I guess I'll have to fetch all records and filter after the fact. A real shame.


  2. ERNEST Olivier (ENGIE IT) 1 Reputation point
    2022-03-20T10:27:24.59+00:00

    Solution come from Powershell self , let's take constructor VMWare that has spaces in all his serials , you can easily do this :

    $SerialWithSpaces = "VMware-XX XX XX XX XX XX XX XX-XX XX XX XX XX XX XX XX"
    $Serial = $SerialWithSpaces.split(" ")
    $uri = "https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeviceIdentities?`$filter=contains(serialNumber,'$($Serial[0])')"
    $tmp = (Invoke-RestMethod -Uri $uri -Method GET -Headers $token).value | where {$_.serialNumber -eq "$($SerialWithSpaces)"}

    in another world just filter on the start on your serial to limit the returned data and then use Powershell strength to isolate the one you want
    You can combine filter to reduce the first amount of data returned using a more complex filter expression


  3. ERNEST Olivier (ENGIE IT) 1 Reputation point
    2022-03-21T06:27:34.167+00:00

    Hello

    i agree if you expect more than 1000 items to be returned by the filter the trick will not work as you must go and check the rest of the results using pagination.

    What's funny is that the Microsoft allowed usage of EQ in deviceManagement/importedwindowsAutopilotDeviceIdentities and from all i read EQ allow to escape space using %20
    so question is why Microsoft allow it in one api and not another one ? which reason do that ?

    and agree By design as it even don't work in their GUI of Intune

    We have same issue at works and i tried to find a workaround for a colleague strungling the same issue as you
    This is the only one working

    Even tray to combine multiple contains in the filter using and but only the first one is taken (bug also i believe)

    0 comments No comments