Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SharePoint Powershell CAML查询中的更改未生效_Powershell_Sharepoint_Caml - Fatal编程技术网

SharePoint Powershell CAML查询中的更改未生效

SharePoint Powershell CAML查询中的更改未生效,powershell,sharepoint,caml,Powershell,Sharepoint,Caml,在我对SharePoint Power shell脚本的CAML查询中,在CAML查询中所做的更改不会生效 我可以知道我在下面的代码片段中做错了什么吗 cls Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Set config variables $baseUrl="http://test.com/" $RDlistName ="RecordsDocument/Forms/TestRepo

在我对SharePoint Power shell脚本的
CAML
查询中,在
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
}
我的测试脚本(希望有帮助):

if((获取PSSnapin“Microsoft.SharePoint.PowerShell”-ErrorAction SilentlyContinue)-eq$null){
在“Microsoft.SharePoint.PowerShell”中添加PSSnapin
}
#设置配置变量
$baseUrl=”http://site/"
$RDlistName=“MyDoc”
#获取Web并列出对象
$web=获取SPWeb$baseUrl
$RDlist=$web.Lists[$RDlistName]
#定义CAML查询
$RDquery=新对象Microsoft.SharePoint.SPQuery
$RDquery.Query=”@
文件夹
"
#获取与查询匹配的列表项
$RDitems=$RDlist.GetItems($RDquery)
$RDcount=1
写入主机“RecordsDocument中的文件夹总数:$RDitems.count”
写入主机“”
#循环浏览每个项目
ForEach($RDitem中的$RDitems)
{
#做点什么
写入主机$RDcount“.”$RDitem[“Title”]“|”$RDitem[“ContentType”]
foreach($RDitem.RoleAssignments中的RDroleAssignment)
{
写入主机-$rdroleasignment.Member.Name
}
$RDcount+=1
}

使用此$RDlist.GetItems($RDquery)和文件夹内容类型过滤使用此FolderHi@JayneshSharma,我已将其更改为
($RDquery)
,但出现了相同的错误。我也修改了我的帖子。你的列表名不能像这样使用列表标题或类似($RDlistName=“RecordsDocument”)。而不是url
+ 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
}