DRiley Posted March 16, 2023 Posted March 16, 2023 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. Thanks, Dan
Steve Giller Posted March 16, 2023 Posted March 16, 2023 @DRiley I'm sure this is just a typo, but should there be a back-tick in the URL? It stands out as an unusual character to be using in that context, but I'm not familiar with InTune so apologies if that's the expected syntax.
SamS Posted March 16, 2023 Posted March 16, 2023 @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.
DRiley Posted March 16, 2023 Author Posted March 16, 2023 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, Dan
Steve Giller Posted March 16, 2023 Posted March 16, 2023 1 hour ago, DRiley said: I was aware of the back-tick being an escape character. I wasn't - I didn't even know it was basically PowerShell (or I'd have recognised the back-tick's purpose!)
SamS Posted July 18, 2023 Posted July 18, 2023 @DRiley, 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. 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now