回答

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循环外。

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() 
相关问题