# Simple question about Filter or Where

**URL:** <https://forums.powershell.org/t/simple-question-about-filter-or-where/13431>\
**Category:** PowerShell Help\
**Created:** [November 18, 2019, 4:36pm UTC](https://forums.powershell.org/t/simple-question-about-filter-or-where/13431 "2019-11-18T16:36:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![parisi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/parisi/32/87_2.png) [@parisi](https://forums.powershell.org/u/parisi)\
**Post date:** [November 18, 2019, 4:36pm UTC](https://forums.powershell.org/t/simple-question-about-filter-or-where/13431/1 "2019-11-18T16:36:48Z")

</div>

How do I filter the Get-LocalUser output?

I am just learning filtering and/or where-object and need some pointers… what is the right way to do the following?

`Get-LocalUser | Select Name, UserMayChangePassword | Where-Object “UserMayChangePassword=‘True’”`

Thanks in advance!

Paul

---

<div class="post-metadata">

**Author:** ![grokkit](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grokkit/32/970_2.png) [@grokkit](https://forums.powershell.org/u/grokkit)\
**Post date:** [November 18, 2019, 5:07pm UTC](https://forums.powershell.org/t/simple-question-about-filter-or-where/13431/2 "2019-11-18T17:07:51Z")

</div>

You’re almost there, just change your Where-Object statement to this:

```
Where-Object "UserMayChangePassword" -eq 'True'
```

In general, when you wrap something in quotes the shell treats it as a single string, so with your statement like this:  
Where-Object “UserMayChangePassword=‘True’”  
you’re telling the shell to find an object with a property name like

```
UserMayChangePassword='True'
```

which of course doesn’t work. The property name and value have to be fed to Where-Object as separate pieces of information.

In addition, the syntax for Where-Object requires that you use the logical comparator **-eq** rather than the arithmetic operator **=** (simply put, you’re doing _logic_, not _math_).

---

<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:** [November 19, 2019, 8:23am UTC](https://forums.powershell.org/t/simple-question-about-filter-or-where/13431/3 "2019-11-19T08:23:19Z")

</div>

That about covers it, nice job! I’d just like to point out that `=` isn’t really an arithmetic operator, it’s just an assignment operator. In PS, `=` is only ever used to assign a value to something. That value may be the result of some arithmetic operation, or it may be any number of other possible values. `$value = @{}` doesn’t involve any arithmetic, but it does involve assignment. 🙂

For more on operators (and `Where-Object` in great detail) I’d recommend [PSKoans](http://aka.ms/pskoans)’ `AboutAssignmentAndArithmetic` and `AboutWhereObject` topics.

---

<div class="post-metadata">

**Author:** ![parisi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/parisi/32/87_2.png) [@parisi](https://forums.powershell.org/u/parisi)\
**Post date:** [November 19, 2019, 8:43am UTC](https://forums.powershell.org/t/simple-question-about-filter-or-where/13431/4 "2019-11-19T08:43:34Z")

</div>

Thank you so much - I will admit that I do not understand it yet but this helped tremendously.

Thanks,

Paul.

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [November 19, 2019, 11:08am UTC](https://forums.powershell.org/t/simple-question-about-filter-or-where/13431/5 "2019-11-19T11:08:56Z")

</div>

The longer form:

```
Where-Object { $_.UserMayChangePassword -eq $true }
```

---

<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/simple-question-about-filter-or-where/13431/6 "2024-05-16T20:31:07Z")

</div>


