# Help with StartsWith filter in Powershell

**URL:** <https://forums.powershell.org/t/help-with-startswith-filter-in-powershell/22269>\
**Category:** PowerShell Help\
**Created:** [May 6, 2023, 9:59pm UTC](https://forums.powershell.org/t/help-with-startswith-filter-in-powershell/22269 "2023-05-06T21:59:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott-windmiller](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@scott-windmiller](https://forums.powershell.org/u/scott-windmiller)\
**Post date:** [May 6, 2023, 9:59pm UTC](https://forums.powershell.org/t/help-with-startswith-filter-in-powershell/22269/1 "2023-05-06T21:59:56Z")

</div>

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

```auto
$uri1 = "https://graph.microsoft.com/beta/deviceManagement/managedDevices?`$filter=startswith(Devicename, 'PSY-')"

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

```

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?  
Thanks!

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [May 7, 2023, 9:59am UTC](https://forums.powershell.org/t/help-with-startswith-filter-in-powershell/22269/2 "2023-05-07T09:59:16Z")

</div>

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](https://www.petervanderwoude.nl/post/getting-started-with-filtering-and-selecting-microsoft-intune-data-via-microsoft-graph/) and [this StackOverflow question](https://stackoverflow.com/questions/75133331/filter-for-dedicated-devices-graph-api).

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

```auto
$results | Where-Object { $_.deviceName -like 'PSY-*' }

```

---

<div class="post-metadata">

**Author:** ![scott-windmiller](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@scott-windmiller](https://forums.powershell.org/u/scott-windmiller)\
**Post date:** [May 8, 2023, 11:42am UTC](https://forums.powershell.org/t/help-with-startswith-filter-in-powershell/22269/3 "2023-05-08T11:42:18Z")

</div>

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

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

Scott

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/help-with-startswith-filter-in-powershell/22269/4 "2024-05-16T20:14:55Z")

</div>


