0

I'm trying to reconfigure scripts I made to move list items from one list to another. At the time the list were not going to change so all the variables were hard coded.

Is it possible to use a PowerShell variable in a CAML query?

for example

$IDNum = 2

$query = '<query>
<where>
<eq>
<FieldRef Name="ID"
<Value Type="Number">$IDNum</value>
</eq>
</where>
</query>'

1 Answer 1

2

Double quoted string expand variables and single quoted strings do not. Use like this:

$query = "<query>
<where>
<eq>
<FieldRef Name="ID"
<Value Type="Number">$IDNum</value>
</eq>
</where>
</query>"

http://blogs.msdn.com/b/powershell/archive/2006/07/15/variable-expansion-in-strings-and-herestrings.aspx

1
  • I've always seen it as $($IDNum), did not know the parentheses were not needed. Learned something new today :)
    – wjervis
    Sep 16, 2014 at 15:08

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.