-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGet-NestedFoldersAndFilesForOneDocLib.ps1
46 lines (41 loc) · 1.84 KB
/
Get-NestedFoldersAndFilesForOneDocLib.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<#
.SYNOPSIS
Export info from a SharePoint site.
.DESCRIPTION
This script will loop through the specific document library & export the number of nested folders, files count, folder size (and more).
.EXAMPLE
PS C:\> .\Get-NestedFoldersAndFilesForOneDocLib.ps1
.INPUTS
Inputs (if any)
.OUTPUTS
System.Object[]
.NOTES
How to use this script is available on my blog at:
https://veronicageek.com/sharepoint/sharepoint-2013/get-nested-folders-files-count-folder-size-and-more-in-spo-document-libraries-using-powershell-pnp/2019/09/
#>
#Connect to SPO -- Change to your tenant name and site
Connect-PnPOnline -Url "https://<TENANT-NAME>.sharepoint.com/sites/<YOUR-SITE>"
#Target a specific lists -- Change to YOUR OWN LIST NAME
$myList = "/Shared Documents"
#Store the results
$results = @()
foreach ($row in $myList) {
$allItems = Get-PnPListItem -List $myList -Fields "FileLeafRef", "SMTotalFileStreamSize", "FileDirRef", "FolderChildCount", "ItemChildCount"
foreach ($item in $allItems) {
#Narrow down to folder type only
if (($item.FileSystemObjectType) -eq "Folder") {
$results += New-Object psobject -Property @{
FileType = $item.FileSystemObjectType #This will return a column with "Folder"
RootFolder = $item["FileDirRef"]
LibraryName = $myList
FolderName = $item["FileLeafRef"]
FullPath = $item["FileRef"]
FolderSizeInMB = ($item["SMTotalFileStreamSize"] / 1MB).ToString("N")
NbOfNestedFolders = $item["FolderChildCount"]
NbOfFiles = $item["ItemChildCount"]
}
}
}
}
#Export the results
$results | Export-Csv -Path "C:\Users\$env:USERNAME\Desktop\NestedFoldersForONEdoclib.csv" -NoTypeInformation