# Script Filter understanding

**URL:** <https://forums.powershell.org/t/script-filter-understanding/23738>\
**Category:** PowerShell Help\
**Created:** [March 8, 2024, 2:46pm UTC](https://forums.powershell.org/t/script-filter-understanding/23738 "2024-03-08T14:46:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwitr](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dwitr](https://forums.powershell.org/u/dwitr)\
**Post date:** [March 8, 2024, 2:46pm UTC](https://forums.powershell.org/t/script-filter-understanding/23738/1 "2024-03-08T14:46:57Z")

</div>

Hi, im new here and new to powershell.

I’m trying to get a value out of a query - the query is working (need to have it 1 line):

`Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select -ExpandProperty LicenseStatus`

That one isnt - but i cant understand whats the difference?

`powershell -executionpolicy bypass -Command "& {Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select -ExpandProperty LicenseStatus}"`

Why is there a problem with "position parameter “like”?

Thank you!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 8, 2024, 8:05pm UTC](https://forums.powershell.org/t/script-filter-understanding/23738/2 "2024-03-08T20:05:42Z")

</div>

dwitr,  
Welcome to the forum. 👋🏼

Quoting can be challenging in PowerShell.

```auto
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -NoProfile -Command "& {Get-CimInstance -ClassName SoftwareLicensingProduct -Filter """Name like 'Windows%'""" | Where-Object -Property PartialProductKey | Select-Object -ExpandProperty LicenseStatus}"

```

When you post more than just a single cmdlet you should use a code block instead of inline code. This you don’t end up with unwanted line breaks. 😉

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( \</\> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

[How to format code in PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) 1 \<---- Click 👆🏽 😉

( !! Sometimes the _preformatted text_ button hides behind the settings gear symbol. 😉 )

---

<div class="post-metadata">

**Author:** ![dwitr](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dwitr](https://forums.powershell.org/u/dwitr)\
**Post date:** [March 11, 2024, 7:19am UTC](https://forums.powershell.org/t/script-filter-understanding/23738/3 "2024-03-11T07:19:56Z")

</div>

Hi Olaf,

thank you 🙂 - but with that line - i just get an

`the string has no graduation sign: "` (sorry my error message is in german)

but i dont see that there is an open “”

Thank you!

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 11, 2024, 7:23am UTC](https://forums.powershell.org/t/script-filter-understanding/23738/4 "2024-03-11T07:23:11Z")

</div>

How do you run this command line? CMD? PowerShell? Something else?

---

<div class="post-metadata">

**Author:** ![dwitr](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dwitr](https://forums.powershell.org/u/dwitr)\
**Post date:** [March 12, 2024, 7:54am UTC](https://forums.powershell.org/t/script-filter-understanding/23738/5 "2024-03-12T07:54:49Z")

</div>

Hi,

ha ok i get it in Powershell - the same cmd in a cmd shell is working.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 12, 2024, 8:05am UTC](https://forums.powershell.org/t/script-filter-understanding/23738/6 "2024-03-12T08:05:49Z")

</div>

Hmmm … does that mean your issue is solved?

---

<div class="post-metadata">

**Author:** ![dwitr](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@dwitr](https://forums.powershell.org/u/dwitr)\
**Post date:** [March 12, 2024, 8:17am UTC](https://forums.powershell.org/t/script-filter-understanding/23738/7 "2024-03-12T08:17:22Z")

</div>

Hi,

yes in that case - thank you.  
But for understanding why is it working in cmd but not in powershell?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 12, 2024, 8:21am UTC](https://forums.powershell.org/t/script-filter-understanding/23738/8 "2024-03-12T08:21:31Z")

</div>

Because `CMD` and `PowerShell` have different quoting rules and therefor treat quotes differently.

Here you can read a little more about

> **[about Quoting Rules - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.4)**
>
> Describes rules for using single and double quotation marks in PowerShell.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [April 11, 2024, 8:21am UTC](https://forums.powershell.org/t/script-filter-understanding/23738/9 "2024-04-11T08:21:50Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
