dwitr
March 8, 2024, 2:46pm
1
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!
Olaf
March 8, 2024, 8:05pm
2
dwitr,
Welcome to the forum.
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.
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 1 <---- Click
( !! Sometimes the preformatted text button hides behind the settings gear symbol. )
dwitr
March 11, 2024, 7:19am
3
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!
Olaf
March 11, 2024, 7:23am
4
How do you run this command line? CMD? PowerShell? Something else?
dwitr
March 12, 2024, 7:54am
5
Hi,
ha ok i get it in Powershell - the same cmd in a cmd shell is working.
Olaf
March 12, 2024, 8:05am
6
Hmmm … does that mean your issue is solved?
dwitr
March 12, 2024, 8:17am
7
Hi,
yes in that case - thank you.
But for understanding why is it working in cmd but not in powershell?
Olaf
March 12, 2024, 8:21am
8
Because CMD
and PowerShell
have different quoting rules and therefor treat quotes differently.
Here you can read a little more about
system
Closed
April 11, 2024, 8:21am
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.