我有一个包含许多文件夹的文档库。 我想获得此库中每个文件夹中的项目的数量。SharePoint CSOM Powershell - 获取库中每个文件夹中的文件数
我想了解这是否可以使用CSOM Powershell来实现。
有什么OOTB方式吗?
我有一个包含许多文件夹的文档库。 我想获得此库中每个文件夹中的项目的数量。SharePoint CSOM Powershell - 获取库中每个文件夹中的文件数
我想了解这是否可以使用CSOM Powershell来实现。
有什么OOTB方式吗?
就像一个预警,我不知道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
循环外。
在文件夹中的文件数量可能通过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()