如何通过powershell在sharepoint中查询特定视图
因此,我一直在尝试查询sharepoint中列表的特定视图。该视图称为“挂起”,但我不确定在代码中的何处应用该视图如何通过powershell在sharepoint中查询特定视图,powershell,sharepoint,Powershell,Sharepoint,因此,我一直在尝试查询sharepoint中列表的特定视图。该视图称为“挂起”,但我不确定在代码中的何处应用该视图 Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) { $list = $Context.Web.Lists.GetByTitle($listTitle) $qry = [Microsoft.SharePoint.Client.CamlQuer
Function Get-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
$list = $Context.Web.Lists.GetByTitle($listTitle)
$qry = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
$items = $list.GetItems($qry)
$Context.Load($items)
$Context.ExecuteQuery()
return $items}
它目前只接收列表中的每个条目,不管它们在哪个视图中,但我希望它只查询“挂起”的条目 您需要使用视图名称的额外参数来扩展该函数 我自己无法测试,但这可能对您有用:
function Get-ListItemsFromView {
[CmdletBinding()]
Param(
[Parameter(Position = 0, Mandatory = $true)]
[Microsoft.SharePoint.Client.ClientContext]$Context,
[Parameter(Position = 1, Mandatory = $true)]
[string]$ViewName,
[Parameter(Position = 2, Mandatory = $true)]
[string]$ListTitle
)
$list = $Context.Web.Lists.GetByTitle($listTitle)
$Context.Load($list)
$Context.ExecuteQuery()
$view = $list.Views.GetByTitle($ViewName)
$Context.Load($view)
$Context.ExecuteQuery()
$qry = New-Object Microsoft.SharePoint.Client.CamlQuery
$qry.ViewXml = $view.ViewQuery
$items = $list.GetItems($qry)
$Context.Load($items)
$Context.ExecuteQuery()
return $items
}
视图不是SharePoint中的数据类型。SharePoint只知道
列表
和库
对象。视图只是由SharePoint创建的ASP.NET Web表单页面。筛选列表中的审批状态
列必须是您要查找的内容
function Get-PendingListItems
{
[CmdletBinding()]
[OutputType([Microsoft.SharePoint.Client.ListItemCollection])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$false,
Position=0)]
[Microsoft.SharePoint.Client.ClientContext]
$Context,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$false,
Position=1)]
[String]
$ListTitle
)
Process
{
# Fail Fast
try {
$list = $Context.Web.Lists.GetByTitle($ListTitle)
} catch {
Write-Error "The list $ListTitle does not exist."
return $null
}
$query = New-Object Microsoft.SharePoint.SPQuery;
# You can select the fields you would like to view. For more information look at: https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ms470490(v=office.14)
# $query.ViewFields = '<ViewFields><FieldRef Name="ID"></FieldRef><FieldRef Name="Title"></FieldRef></ViewFields>';
# 2 means pending. For More information look at: https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spmoderationstatustype?view=sharepoint-server
$query.Query = '<Where><Eq><FieldRef Name="_ModerationStatus" /><Value Type="ModStat">2</Value></Eq></Where>';
$items = $list.GetItems($query)
$Context.Load($items)
$Context.ExecuteQuery()
return $items
}
End
{
$Context.Dispose()
}
}
函数获取PendingListItems
{
[CmdletBinding()]
[OutputType([Microsoft.SharePoint.Client.ListItemCollection])]
Param
(
[参数(必需=$true,
ValueFromPipelineByPropertyName=$false,
位置=0)]
[Microsoft.SharePoint.Client.ClientContext]
$Context,
[参数(必需=$true,
ValueFromPipelineByPropertyName=$false,
职位=1)]
[字符串]
$ListTitle
)
过程
{
#快速失败
试一试{
$list=$Context.Web.Lists.GetByTitle($ListTitle)
}抓住{
写入错误“列表$ListTitle不存在。”
返回$null
}
$query=新对象Microsoft.SharePoint.SPQuery;
#您可以选择要查看的字段。有关详细信息,请参阅:https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ms470490(v=办公室14)
#$query.ViewFields='';
#2表示待定。有关更多信息,请参阅:https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spmoderationstatustype?view=sharepoint-服务器
$query.query='2';
$items=$list.GetItems($query)
$Context.Load($items)
$Context.ExecuteQuery()
退回$items
}
终点
{
$Context.Dispose()
}
}
在这里,我们创建了一个CAML查询,该查询只过滤审批状态为待定的项目。数字2
表示Pending
,如图中所示。您可以筛选要返回的属性,但我已经注释掉了该行,因为它不是必需的。你可以在墙上看看