File SharePoint CSOM Powershell-获取库中每个文件夹中的文件数

File SharePoint CSOM Powershell-获取库中每个文件夹中的文件数,file,powershell,count,sharepoint-2013,sharepointdocumentlibrary,File,Powershell,Count,Sharepoint 2013,Sharepointdocumentlibrary,我有一个包含许多文件夹的文档库。 我想获取此库中每个文件夹中的项目数 我想了解是否可以使用CSOM Powershell实现这一点 有什么办法吗 作为预警,我不确定CSOM Powershell是否具有与传统Powershell相同的cmdlet。让我知道如果他们这样做,我会摆脱这个职位。如果没有,这应该是可行的: 假设结构中有[library]包含[folders]包含所有要计数的文件 foreach($folder in (Get-ChildItem $[library])){

我有一个包含许多文件夹的文档库。 我想获取此库中每个文件夹中的项目数

我想了解是否可以使用CSOM Powershell实现这一点


有什么办法吗

作为预警,我不确定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
循环之外有多少项。

可以通过检索文件夹中的文件数,下面的示例演示了如何获取每个文件夹的文件数:

$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() 
$ctx=新对象Microsoft.SharePoint.Client.ClientContext($siteUrl)
$ctx.Credentials=新对象系统.Net.NetworkCredential($username、$password、$domain)
$list=$ctx.Web.Lists.GetByTitle(“文档”)
$query=新对象Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml=”
1.
"
$items=$list.GetItems($query)
$ctx.Load($items)
$ctx.ExecuteQuery()
$items.GetEnumerator()|%{
写入主机$[“FileRef”],“:”,$[“ItemChildCount”]
}
$ctx.Dispose()