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 :) Commented Sep 16, 2014 at 15:08

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.