SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have written a script to get the items of a specific list leveraging the GetListItems method, but I am now being asked to join multiple lists, so I believe I must use the GetItems method. The code is essentially the same, but I am not able to get the fields back that I need. I have removed the joins and preferredfields nodes to simplify the code below. I would welcome your input:

#Region Configure for Remote Execution
$pass = ConvertTo-SecureString "******" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList "domain\user", $pass
Enter-PSSession -ComputerName SPSERVER-Authentication CredSSP -Credential:$creds
Add-PSSnapin Microsoft.SharePoint.PowerShell

$list = $web.GetList("http://webapp/site/Lists/ServerCatalog")
$query = new-object Microsoft.SharePoint.SPQuery

$query.query = [xml]@"
              <Neq><FieldRef Name='DeploymentStatus' /><Value Type='MultiChoice'>Build</Value></Neq>
              <Neq><FieldRef Name='DeploymentStatus' /><Value Type='MultiChoice'>Inactive</Value></Neq>
                        <Eq><FieldRef Name='Team' /><Value Type='Text'>AD</Value></Eq>
                        <Eq><FieldRef Name='App_x0020_Server' /><Value Type='bit'>1</Value></Eq>
                        <Eq><FieldRef Name='Web_x0020_Server' /><Value Type='bit'>1</Value></Eq>
                        <Eq><FieldRef Name='SQL_x0020_DB' /><Value Type='bit'>1</Value></Eq>
              <Eq><FieldRef Name='Desktop' /><Value Type='bit'>1</Value></Eq>

$query.ViewFields = [xml]@"
     <FieldRef Name="ows_Title" />
    <FieldRef Name="MgmtIP" />
     <FieldRef Name="OU" />
     <FieldRef Name="CNAMES" />
     <FieldRef Name="Processes" />
     <FieldRef Name="URLs" />
     <FieldRef Name="IgnoreURLs" />
     <FieldRef Name="SQL_x0020_Accounts" />
     <FieldRef Name="SQLStatements" />
     <FieldRef Name="App_x0020_Server" />
     <FieldRef Name="SQL_x0020_DB" />
     <FieldRef Name="Web_x0020_Server" />
     <FieldRef Name="Desktop" />
     <FieldRef Name="DeploymentStatus" />    
$query.IncludeMandatoryColumns = $false
$query.DatesInUtc = $true
$items = $list.GetItems($query)

share|improve this question

If you need to query multiple lists with the same CAML query you probably want to do the SPSiteDataQuery route:

You use the Lists properties of the class to specify which lists ( template, base type, or explicit) are included in the search:

share|improve this answer
I will evaluate this alternative method, but there is nothing wrong with leveraging GetItems() against multiple lists. – websch01ar Aug 8 '11 at 11:21
If you want to execute the method against each list individually and then manually join the results then you're right there is nothing wrong with leveraging GetItems...I have offered up an alternative that will not require that extra work. – Rob D'Oria Aug 8 '11 at 13:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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