# Problème with variable

**URL:** <https://forums.powershell.org/t/probleme-with-variable/12975>\
**Category:** PowerShell Help\
**Created:** [August 9, 2019, 7:34am UTC](https://forums.powershell.org/t/probleme-with-variable/12975 "2019-08-09T07:34:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seb](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@seb](https://forums.powershell.org/u/seb)\
**Post date:** [August 9, 2019, 7:34am UTC](https://forums.powershell.org/t/probleme-with-variable/12975/1 "2019-08-09T07:34:33Z")

</div>

Hello,

&nbsp;

I try to use variable in -filter with \* but i don’t find the good syntax maybe someone can help me ?

try this powershell :

display a users who have variable in his name

get-asuser -filter {name -like _$group_} not work NEED THIS

get-asuser -filter {name -like $group}work but without \*

get-aduser -filter {name -like “_sale_”} work but i need replace sale by a variable …

THX !

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![seb](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@seb](https://forums.powershell.org/u/seb)\
**Post date:** [August 9, 2019, 8:58am UTC](https://forums.powershell.org/t/probleme-with-variable/12975/2 "2019-08-09T08:58:44Z")

</div>

i have find a replace “solution” 🙂

put my variable in a new one with \* after and before and it work … if someone have the “true” and proper syntax respond this post with

$test = “_$group_”

get-asuser -filter {name -like $test} (result, get-aduser -filter -like _sale_, if group=sale)

---

<div class="post-metadata">

**Author:** ![ta11ow](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ta11ow/32/131_2.png) [@ta11ow](https://forums.powershell.org/u/ta11ow)\
**Post date:** [August 9, 2019, 10:43am UTC](https://forums.powershell.org/t/probleme-with-variable/12975/3 "2019-08-09T10:43:20Z")

</div>

Despite all the cmdlets’ help documentation on `-Filter`, braces aren’t the best syntax. Very restrictive in what you can / can’t do.

```
Get-ADUser -Filter "name -like '*$test*'"
```

---

<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:31pm UTC](https://forums.powershell.org/t/probleme-with-variable/12975/4 "2024-05-16T20:31:51Z")

</div>

Closed on May 16, 2024, 8:31pm UTC


