我有一个包含许多文件夹的文档库。 我想得到这个库中每个文件夹中的项目数。
我想了解是否可以使用CSOM Powershell实现这一目标。
有没有OOTB方式?
答案 0 :(得分:0)
正如预警一样,我不确定CSOM Powershell是否具有与传统PowerShell相同的cmdlet。让我知道他们是否这样做,我将摆脱这篇文章。如果没有,这应该有效:
假设一个结构中[library]
包含[folders]
,其中包含您要计算的所有文件。
foreach($folder in (Get-ChildItem $[library])){
$filecount = 0
Get-ChildItem $folder -recurse |
%{$filecount += 1}
#do whatever you want with $filecount here.
}
您可以使用字典或其他数据结构来计算foreach
循环之外哪些文件夹包含多少项。
答案 1 :(得分:0)
可以通过ItemChildCount
field检索文件夹中的文件数量,这是一个演示如何获取每个文件夹的文件编号的示例:
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain)
$list = $ctx.Web.Lists.GetByTitle("Documents")
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = "<View Scope='RecursiveAll'>
<ViewFields>
<FieldRef Name='FileRef' />
<FieldRef Name='ItemChildCount' />
</ViewFields>
<Query>
<Where>
<Eq>
<FieldRef Name='FSObjType' />
<Value Type='Integer'>1</Value>
</Eq>
</Where>
</Query>
</View>"
$items = $list.GetItems($query)
$ctx.Load($items)
$ctx.ExecuteQuery()
$items.GetEnumerator() | % {
Write-Host $_["FileRef"] , ":" , $_["ItemChildCount"]
}
$ctx.Dispose()