未采用 SharePoint Powershell CAML 查询效果中的更改

Changes in SharePoint Powershell CAML Query Effect not Taken

在我的 CAML 查询 SharePoint Power-shell 脚本中,在 CAML 查询中所做的更改未生效。

我可以知道我在下面的代码片段中做错了什么吗?

cls
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set config variables
$baseUrl="http://test.com/"
$RDlistName ="RecordsDocument/Forms/TestReport"

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

#Define the CAML Query
$RDquery = New-Object Microsoft.SharePoint.SPQuery
$RDquery.Query = "@
<Where>
    <Eq>
        <FieldRef Name='ContentType' />
        <Value Type='Text'>Folder Content Type</Value> 
        #changes to above filter with an incorrect value still returns result *****
    </Eq>
</Where>"

#Get List Items matching the query
$RDitems = $RDlist.GetItems($RDquery)
$RDcount = 1

Write-host "Total Number of Folders in RecordsDocument:"$RDitems.count
Write-host ""

#Loop through Each Item
ForEach($RDitem in $RDitems)
{
    #Do something
    Write-host $RDcount"." $RDitem["Title"] "|" $RDitem["ContentType"]

    foreach($RDroleAssignment in $RDitem.RoleAssignments)  
    {
        Write-Host - $RDroleAssignment.Member.Name
    }
    $RDcount +=1
}

编辑:此外,观察到以下错误..

You cannot call a method on a null-valued expression. At

D:\User\test.ps1:25 char:1

  • $RDitems = $RDlist.GetItems($RDquery)

  • + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
    

我的测试脚本(希望有帮助):

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

#Set config variables
$baseUrl="http://site/"
$RDlistName ="MyDoc"

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

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

#Get List Items matching the query
$RDitems = $RDlist.GetItems($RDquery)
$RDcount = 1

Write-host "Total Number of Folders in RecordsDocument:"$RDitems.count
Write-host ""

#Loop through Each Item
ForEach($RDitem in $RDitems)
{
    #Do something
    Write-host $RDcount"." $RDitem["Title"] "|" $RDitem["ContentType"]

    foreach($RDroleAssignment in $RDitem.RoleAssignments)  
    {
        Write-Host - $RDroleAssignment.Member.Name
    }
    $RDcount +=1
}