Script Filter understanding

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!

Welcome to the forum. :wave:t3:

Quoting can be challenging in PowerShell.

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. :wink:

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 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

Hi Olaf,

thank you :slight_smile: - 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!

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


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

Hmmm … does that mean your issue is solved?


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

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

Here you can read a little more about

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