SharePoint powershell to retrieve count of files in 2nd level subfolder in all subsites

%3CLINGO-SUB%20id%3D%22lingo-sub-2209071%22%20slang%3D%22en-US%22%3ESharePoint%20powershell%20to%20retrieve%20count%20of%20files%20in%202nd%20level%20subfolder%20in%20all%20subsites%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2209071%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3CBR%20%2F%3EHow%20to%20generate%20a%20report%20in%20csv%20to%20count%20of%20all%20files%20present%20in%202nd%20level%20subfolder%20%5BChange%20Requests%5D%20in%20all%20subsites%26nbsp%3B%20%3CA%20href%3D%22https%3A%2F%2Fwww.sharepointdiary.com%2F2017%2F03%2Fget-all-list-and-libraries-inventory-of-site-collection-using-powershell.html%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Elike%3C%2FA%3E%3C%2FP%3E%3CP%3EI%20have%20edited%20source%20from%20this%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fsharepointrelated.com%2F2014%2F11%2F11%2Fdownload-all-content-in-a-site-collection%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Elink%3C%2FA%3E%20...%26nbsp%3B%3C%2FP%3E%3CP%3E%24lists%20%3D%20%24web.lists%20%7C%20%3F%7B%24_.title%20-eq%20%22Documents%22%20-and%20%24_.itemcount%20-ge%20%221%22%20-And%20%24_.BaseType%20-eq%20%22DocumentLibrary%22%7D%20%23Change%20any%20identifier%20here%3CBR%20%2F%3Eforeach(%24list%20in%20%24lists)%3CBR%20%2F%3E%7B%3CBR%20%2F%3EWrite-Host%20%22-%20%24(%24list.RootFolder.url)%22%3CBR%20%2F%3E%24DirpathList%20%3D%20%24Dirpath%20%2B%22%5C%22%2B%24list.title%3CBR%20%2F%3ECreateFolder(%24DirpathList)%3CBR%20%2F%3E%23Download%20files%20in%20root%20folder%3CBR%20%2F%3E%23%24rootfolder%20%3D%20%24web.GetFolder(%24list.RootFolder.Url)%3CBR%20%2F%3E%23Download-SPContent(%24rootfolder)%3C%2FP%3E%3CP%3E%23Download%20files%20in%20subfolders%3CBR%20%2F%3Eforeach(%24folder%20in%20%24list.folders)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23%24folder%20%3D%20%24web.GetFolder(%24folder.url)%3CBR%20%2F%3Eif%20(%24folder.name%20-eq%20%22%3CSTRONG%3EChange%20Requests%3C%2FSTRONG%3E%22)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%24folder%20%3D%20%24web.GetFolder(%24folder.url)%3CBR%20%2F%3EDownload-SPContent(%24folder)%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3EThanks%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi,
How to generate a report in csv to count of all files present in 2nd level subfolder [Change Requests] in all subsites  like

I have edited source from this link ... 

$lists = $web.lists | ?{$_.title -eq "Documents" -and $_.itemcount -ge "1" -And $_.BaseType -eq "DocumentLibrary"} #Change any identifier here
foreach($list in $lists)
{
Write-Host "- $($list.RootFolder.url)"
$DirpathList = $Dirpath +"\"+$list.title
CreateFolder($DirpathList)
#Download files in root folder
#$rootfolder = $web.GetFolder($list.RootFolder.Url)
#Download-SPContent($rootfolder)

#Download files in subfolders
foreach($folder in $list.folders)
{
#$folder = $web.GetFolder($folder.url)
if ($folder.name -eq "Change Requests")
{
$folder = $web.GetFolder($folder.url)
Download-SPContent($folder)
}
}
}

Thanks



0 Replies