如果修改或删除了CAML查询,SPList不返回结果

问题描述 投票:0回答:1

我有一个SharePoint PowerShell脚本,该脚本从列表中获取项目。

我将CAML查询更改为其他输出。

但是,当更改或删除CAML查询时,list.GetItems()的方法返回了0结果,我不知道为什么会这样。

下面是我的代码段:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set config variables
$baseUrl="http://test.com/"
$listName ="Lists/FilePlan"

#Get Web and List Objects
$web = Get-SPWeb $baseUrl
$list = $web.GetList($listName)

#Define the CAML Query
$queryOriginal = New-Object Microsoft.SharePoint.SPQuery
$queryOriginal.Query = "@
<Where>
    <Eq>
        <FieldRef Name='ContentType' />
        <Value Type='Text'>Folder Content Type</Value>
    </Eq>
</Where>"

$queryModified = New-Object Microsoft.SharePoint.SPQuery
$queryModified.Query = "@
<Where>
    <Eq>
        <FieldRef Name='ContentType' />
        <Value Type='Text'>Document Content Type</Value>
    </Eq>
</Where>"

#Get List Items matching the query
$items = $list.GetItems($queryOriginal)  //result
$items2 = $list.GetItems($queryModified) //zero result*****
$items3 = $list.GetItems()               //zero result*****

编辑:

尝试使用<Neq>,但也无济于事。

list powershell sharepoint caml
1个回答
0
投票

您可以在下面查看PowerShell脚本。

#Set config variables
$baseUrl="http://test.com/"
$listName ="FilePlan"

#Get Web and List Objects
$web = Get-SPWeb $baseUrl
$list = $web.Lists[$listName]

$items = $list.Items
$items.Count

然后您可以检查ContentType是否适合此列表。您可以提供有关列表的更多信息(自定义列表或文档库以及该列表的所有内容类型),以供进一步研究。

© www.soinside.com 2019 - 2024. All rights reserved.