Jump to content

Hornbill Azure InTune Asset Import Runbook script startsWith filter

Recommended Posts

Hi All,

 I'm curious to know if anyone has had any experience filtering InTune devices using the "startsWith" operator in their InTune asset import runbook script? I'm referencing the Microsoft documentation (here: Supported filter device properties and operators in Microsoft Intune | Microsoft Learn )but not having much success.

I appreciate this document is referencing the rule syntax editor in the InTune so I adjusted slightly to go in the script. Unfortunately the result is a "Bad Syntax" response from InTune.

Here's the resource I'm using in my script: "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?`$filter=(operatingSystem eq 'iOS') and (model startsWith 'iPhone')"

Any pointers would be appreciated.


Link to comment
Share on other sites

@DRiley & @Steve Giller,

That backtick should remain in the PowerShell script as it escapes the dollar-sign. The dollar-sign is used in PowerShell to ring in variables, so the backtick prevents that behaviour.

One thing of note in your query is that the "startsWith" syntax usage should be: startswith(model, 'iPhone')

When it comes to testing, I've found MS Graph Explorer to be handy (one would leave out the backtick here), but I've struggled to get the filters working as well - including trying it in beta and adding an extra request header () which was suggested in an article.

As the filtering is Microsoft API, your query should really be directed there.

The alternative (if MS can't explain why the filtering doesn't work) would be to leave out the filter and deal with the filtering in the PowerShell code.

Link to comment
Share on other sites

Thanks Steve, Sam,

 yeah, I was aware of the back-tick being an escape character. I've only been manipulating anything to the right of the = sign.

I also tried, startswith(model, 'iPhone') but this returns all device records which is rather frustrating. Perhaps the same result you experienced Sam?

Either way, thanks for confirming your findings. I wondered if there was a special way to use this operator that I was overlooking, but seems not.

Thanks again guys,



Link to comment
Share on other sites

  • 4 months later...


I've had a chat with MS regarding the OData filtering in InTune. In short: they are aware that not all filtering works AND there is no documentation on what specifically does and doesn't work (eg startsWith doesn't appear to work at all, UNLESS you check the full word - in which case "eq" could/should be used. Things might/should change at some stage in the future.

In the meantime, the best way would be to code the filters within the Runbook - i.e. have a developer implement the following PSEUDO-code:

if ($Device.model = 'iPhone'){
	$AssetType = "123";
} else if ($Device.model = 'iPad' || $Device.make = 'Samsung'){
	$AssetType = "205";
} else skip this import

If the assetClass changes, then some more tinkering will be required.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...