Help with StartsWith filter in Powershell

Trying to get a list of Intune Devices from Graph where their names start with “PSY-”
Running the command below in Powershell:

$uri1 = "`$filter=startswith(Devicename, 'PSY-')"

 $Results = (Invoke-RestMethod -Uri $uri1 -Headers $authToken -Method Get).value

This works but also gives me devices that start with “EPSY-”, another department. Shouldn’t the StartsWith only get devices that specifically start with “PSY-”?

How can I resolve this?

Do all your devices start with EPSY or PSY? I’m trying to work out from your post if it’s returning all devices and the filter is not applying at all, or if it’s applying incorrectly.

There do seem to be problems reported with filtering managed devices:
See the comments on this blog post and this StackOverflow question.

In the absence of other suggestions, I think you’ll have to use Where-Object and have PowerShell do the filtering:

$results | Where-Object { $_.deviceName -like 'PSY-*' }
1 Like

Thanks Matt,
That’s what I am trying out now, thanks!

Yes, it does return all devices and I only want the PSY- results.