forked from PoeBlu/powershell-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCount_Files_Folders.ps1
86 lines (54 loc) · 2.17 KB
/
Count_Files_Folders.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function Get-SPOWebs($url)
{
#fill metadata information to the client context variable
$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$context.Credentials = $SPOcredentials
$web = $context.Web
$context.Load($web)
$context.Load($web.Webs)
$context.load($web.lists)
try{
$context.ExecuteQuery()
#loop through all lists in the web
foreach($list in $web.lists){
add-content -value "<tr><td><span style='margin-left:$($pixelslist)px'>$($list.title)</td><td>List/library</td><td></td><td>$($list.itemcount)</td></tr>" -path $filePath
}
#loop through all webs in the web and start again to find more subwebs
$pixelsweb = $pixelsweb + 15
$pixelslist = $pixelslist + 15
foreach($web in $web.Webs) {
add-content -value "<tr style='background-color:yellow'><td><span style='margin-left:$($pixelsweb)px'>$($web.url)</td><td>Web</td><td>$($web.webtemplate)</td><td></td></tr>" -path $filePath
write-host "Info: Found $($web.url)" -foregroundcolor green
Get-SPOWebs($web.url)
}
}
catch{
write-host "Could not find web" -foregroundcolor red
}
}
$fileCount = 0
$folderCount = 0
$itemcount = 0
# $Web = <Enter URL Here or use -- Read-host “Please enter the Url” To have it ask for the URL >
$Web = Read-host “Please enter the Url”
$WebObject = Get-SPOWebs $Web
$WebObject.Lists | Select Title
# $Library = < Enter Library name Here or use -- Read-Host “Please enter Library or list name” To have it ask for the share Library >
$Library = Read-Host “Please enter Library or list name”
$LibraryObject = $WebObject.Lists[“$Library”]
$itemcount = $LibraryObject.ItemCount
foreach ($folders in $LibraryObject.Folders)
{
$folder = $folders.Folder
$folderCount ++
foreach ($file in $folder.Files)
{
$fileCount ++
$filesizeinkb = ($file.length/1024)
“{0}`t{1}`t{2}” -f $folder.Name, $file.Name, $filesizeinkb | out-file Test.csv> -Append
}
}
Write-Host -ForegroundColor Green “Total Item Count ” $itemcount
Write-Host -ForegroundColor Green “Total File Count ” $fileCount
Write-Host -ForegroundColor Green “Total Folder Count ” $folderCount
$WebObject.Dispose()