I have a powershell script where I need to get some items from SharePoint online list, filtered by one value in string column, and it only works if I put value in quotes.

$Number=123 # NOT working, no values returned from SP
[string]$Number=123 # NOT working, no values returned from SP
$Number="123" # WORKING

and then

$query = "<View><Query><Where><Eq><FieldRef Name='Number'/><Value Type='Text'>$Number</Value></Eq></Where></Query></View>";   
$NumberInfo = (Get-PnPListitem -List SPList -Query $query).FieldValues

Any ideas what I could be doing wrong?

1 Answer 1


Not seeing any issues. Have two columns: One as Single Line of Text and the other Number. Both cases, without quote worked for me. See the test script below.

$Number=45 #worked

$query = "<View><Query><Where><Eq><FieldRef Name='NumberAsText'/><Value Type='Text'>$Number</Value></Eq></Where></Query></View>";   
$NumberInfo = (Get-PnPListitem -List ProjectList -Query $query).FieldValues

$Number=23 #Worked here as well

$query = "<View><Query><Where><Eq><FieldRef Name='NumberAsNumber'/><Value Type='Number'>$Number</Value></Eq></Where></Query></View>";   
$NumberInfo = (Get-PnPListitem -List ProjectList -Query $query).FieldValues

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.