-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPOA-BETA.ps1
1262 lines (1092 loc) · 59.9 KB
/
SPOA-BETA.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region VARIABLES
$global:wordDirtySearch = $null;
$configFilePath = "https://raw.githubusercontent.com/TheRealGoodLivin/SPOA/main/CONFIG.json"
$currentVersion = "1.1"
$setupPath = "C:\users\$env:USERNAME\Documents\SOPA"
$setupReportPath = $setupPath + "\Reports"
$setupDirtyWordsPath = $setupPath + "\DirtyWords"
$setupDirtyWordsFilePath = $setupDirtyWordsPath + "\DirtyWords.csv"
#endregion
#region FUNCTIONS
Function Format-FileSize() { # https://community.spiceworks.com/topic/1955251-powershell-help
Param ([int]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} KB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {""}
}
function reportCreate {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][object[]]$reportData)
if (test-path $reportPath) {
$reportData | export-csv -Path $reportPath -Force -NoTypeInformation -Append
} else {
$reportData | export-csv -Path $reportPath -Force -NoTypeInformation
}
}
function emailValidation {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$email)
return $email -match "^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"
}
#endregion
#region SETUP FUNCTIONS
function showSetup {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$configFilePath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$currentVersion,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$setupPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$dirtyWordsPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$dirtyWordsFilePath)
Clear-Host
try {
$config = (New-Object System.Net.WebClient).DownloadString($configFilePath) | ConvertFrom-Json
$configWords = $config.DirtyWords
$configVersion = $config.version
} catch {
Write-host "`nUNABLE TO DOWNLOAD CONFIG" -ForegroundColor Red
$configWords = @("\d{3}-\d{3}-\d{4}","\d{3}-\d{2}-\d{4}","MyFitness","CUI","UPMR","SURF","PA","2583","SF86","SF 86","FOUO","GTC","medical","AF469","AF 469","469","Visitor Request","VisitorRequest","Visitor","eQIP","EPR","910","AF910","AF 910","911","AF911","AF 911","OPR","eval","feedback","loc","loa","lor","alpha roster","alpha","roster","recall","SSN","SSAN","AF1466","1466","AF 1466","AF1566","AF 1566","1566","SGLV","SF182","182","SF 182","allocation notice","credit","allocation","2583","AF 1466","AF1466","1466","AF1566","AF 1566","1566","AF469","AF 469","469","AF 422","AF422","422","AF910","AF 910","910","AF911","AF 911","911","AF77","AF 77","77","AF475","AF 475","475","AF707","AF 707","707","AF709","AF 709","709","AF 724","AF724","724","AF912","AF 912","912","AF 931","AF931","931","AF932","AF 932","932","AF948","AF 948","948","AF 3538","AF3538","3538","AF3538E","AF 3538E","AF2096","AF 2096","2096","AF 2098","AF2098","AF 2098","AF 3538","AF3538","3538","1466","1566","469","422","travel","SF128","SF 128","128","SF 86","SF86","86","SGLV","SGLI","DD214","DD 214","214","DD 149","DD149","149")
$configVersion = $currentVersion
}
$pnpIsInstalled = Get-InstalledModule -Name PnP.PowerShell -ErrorAction silentlycontinue
if($pnpIsInstalled.count -eq 0) {
$Confirm = read-host "`nWOULD YOU LIKE TO INSTALL SHAREPOINT PNP MODULE? [Y] Yes [N] No"
if($Confirm -match "[yY]") {
install-module -Name PnP.PowerShell -scope currentuser
} else {
write-host "`nSHAREPOINT PNP MODULE IS NEED TO PERFORM THE FEATURES IN THIS SCRIPT." -ForegroundColor red
break
}
} else {
$pnpCurrentModule = ((get-module -Name PnP.PowerShell -listavailable).Version | sort-object -Descending | select-object -First 1).ToString()
$pnpNewestModule = (find-module -Name PnP.PowerShell).Version.ToString()
if ([System.Version]$pnpCurrentModule -lt [System.Version]$pnpNewestModule) {
$Confirm = read-host "`nTHERE IS AN UPDATE TO SHAREPOINT PNP MODULE. WOULD YOU LIKE TO INSTALL IT? [Y] Yes [N] No"
if($Confirm -match "[yY]") {
update-module -Name PnP.PowerShell
}
}
}
#FOLDER AND FILES SETUP
if (-Not (test-path $setupPath)) { New-Item -Path $setupPath -ItemType Directory | out-null }
if (-Not (test-path $reportPath)) { New-Item -Path $reportPath -ItemType Directory | out-null }
if (-Not (test-path $dirtyWordsPath)) {New-Item -Path $dirtyWordsPath -ItemType Directory | out-null }
if (-Not (test-path $dirtyWordsFilePath)) { $configWords | Select-Object @{Name='Word';Expression={$_}} | export-csv $dirtyWordsFilePath -NoType }
if (test-path $dirtyWordsPath) { $global:wordDirtySearch = Import-Csv $dirtyWordsFilePath }
Clear-Host
#CHECK SPOA UPDATE FILE
if ($currentVersion -ne $configVersion) {
write-host "###########################################################" -ForegroundColor Green
write-host "# NEW SPOA UPDATE AVAIABLE #" -ForegroundColor Green
write-host "# https://github.com/TheRealGoodLivin/SPOA/ #" -ForegroundColor Green
write-host "###########################################################`n" -ForegroundColor Green
}
showMain
}
#endregion
#region MAIN AND SETTING MENU FUNCTIONS
function showMain {
write-host "###########################################################"
write-host "# #"
write-host "# " -NoNewline
write-host " ██████ ██▓███ ▒█████ ▄▄▄ " -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host "▒██ ▒ ▓██░ ██▒▒██▒ ██▒▒████▄ " -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host "░ ▓██▄ ▓██░ ██▓▒▒██░ ██▒▒██ ▀█▄ " -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host " ▒ ██▒▒██▄█▓▒ ▒▒██ ██░░██▄▄▄▄██ " -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host "▒██████▒▒▒██▒ ░ ░░ ████▓▒░ ▓█ ▓██▒" -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host "▒ ▒▓▒ ▒ ░▒▓▒░ ░ ░░ ▒░▒░▒░ ▒▒ ▓▒█░" -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host "░ ░▒ ░ ░░▒ ░ ░ ▒ ▒░ ▒ ▒▒ ░" -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host "░ ░ ░ ░░ ░ ░ ░ ▒ ░ ▒ " -ForegroundColor red -NoNewline
write-host " #"
write-host "# " -NoNewline
write-host " ░ ░ ░ ░ ░" -ForegroundColor red -NoNewline
write-host " #"
write-host "# #"
write-host "# WELCOME TO THE SHAREPOINT ONLINE ASSISTANT TOOL #"
write-host "# #"
write-host "###########################################################"
}
function showMenu {
write-host "`nMAIN MENU -- SELECT A CATEGORY`n
`t1: PRESS '1' FOR COLLECTION TOOLS.
`t2: PRESS '2' FOR GROUP TOOLS.
`t3: PRESS '3' FOR USER TOOLS.
`t4: PRESS '4' FOR LIST TOOLS.
`t5: PRESS '5' FOR DOCUMENT TOOLS.
`tS: PRESS 'S' FOR SETTINGS.
`tQ: PRESS 'Q' TO QUIT.`n
FOR HELP TYPE NUMBER AND ADD ? (E.G. 1?)`n"
}
function showSettings {
write-host "`nSETTINGS -- SELECT AN OPTION`n
`t1: PRESS '1' TO OPEN SPOA FOLDER.
`t2: PRESS '2' TO OPEN THE DIRTY WORD LIST.
`tE: PRESS 'E' TO EXIT BACK TO THE MAIN MENU.`n"
}
#endregion
#region SITE TOOLS FUNCTIONS
function showSiteTools {
write-host "`nSITE TOOLS -- SELECT AN OPTION`n
`t1: PRESS '1': SITE MAP REPORT.
`t2: PRESS '2': SITE PII SCAN REPORT.
`t3: PRESS '3': SITE COLLECTION ADMIN REPORT.
`t4: PRESS '4': SITE COLLECTION GROUP REPORT.
`t5: PRESS '5': SITE ADD COLLECTION ADMIN.
`t6: PRESS '6': SITE DELETE COLLECTION ADMIN.
`tE: PRESS 'E' TO EXIT BACK TO THE MAIN MENU.`n
FOR HELP TYPE NUMBER AND ADD ? (E.G. 1?)`n"
}
#region SITE TOOLS FUNCTIONS OPTION "1"
function spoSiteMap {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE COLLECTION URL"
$results = @()
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
$siteInfo = Get-PnPWeb -Includes Created | select Title, ServerRelativeUrl, Url, Created, Description
$siteLists = Get-PnPList | where-object {$_.Hidden -eq $false}
$subSites = Get-PnPSubWeb -Recurse | select Title, ServerRelativeUrl, Url, Created, Description
$siteListCount = @()
$siteItemCount = 0
foreach ($list in $subSiteLists) {
$siteListCount += $list
$siteItemCount = $siteItemCount + $list.ItemCount
}
# GET PARENT SITE INFO AND LIST COUNT
$results = New-Object PSObject -Property @{
Title = $siteInfo.Title
ItemCount = $siteItemCount
ListCount = $siteListCount.count
ServerRelativeUrl = $siteInfo.ServerRelativeUrl
Description = $siteInfo.Description
Created = $siteInfo.Created
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
foreach ($site in $subSites) {
Connect-PnPOnline -Url $site.Url -UseWebLogin -WarningAction SilentlyContinue
$subSiteLists = Get-PnPList | where-object {$_.Hidden -eq $false}
$subSiteListCount = @()
$subSiteItemCount = 0
foreach ($list in $subSiteLists) {
$subSiteListCount += $list
$siteListCount += $list
$subSiteItemCount = $subSiteItemCount + $list.ItemCount
$siteItemCount = $siteItemCount + $list.ItemCount
}
$results = New-Object PSObject -Property @{
Title = $site.Title
ListCount = $subSiteListCount.count
ItemCount = $subSiteItemCount
ServerRelativeUrl = $site.ServerRelativeUrl
Description = $site.Description
Created = $site.Created
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
# GET TOTAL COUNTS
$results = New-Object PSObject -Property @{
Title = "Total"
ListCount = $siteListCount.count
ItemCount = $siteItemCount
ServerRelativeUrl = $subSites.count + 1
Description = ""
Created = ""
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region SITE TOOLS FUNCTIONS OPTION "2"
function spoSiteScanPII {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE COLLECTION URL"
$results = @()
$Confirm = read-host "`nWOULD YOU LIKE TO SCAN ALL SUB-SITES? [Y] Yes [N] No"
if($Confirm -match "[yY]") {
$siteParentOnly = $false
} else {
$siteParentOnly = $true
}
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
$getDocLibs = Get-PnPList | where-object { $_.BaseTemplate -eq 101 }
write-host "Searching: $($sitePath)" -ForegroundColor Green
foreach ($DocLib in $getDocLibs) {
Get-PnPListItem -List $DocLib -Fields "FileRef", "File_x0020_Type", "FileLeafRef", "File_x0020_Size", "Created", "Modified" -PageSize 1000 | Where { $_["FileLeafRef"] -like "*.*" } | foreach-object {
foreach ($word in $global:wordDirtySearch) {
$wordSearch = "(?i)\b$($word.Word)\b"
if (($_["FileLeafRef"] -match $wordSearch)) {
write-host "File found. " -ForegroundColor Red -nonewline; write-host "Under: '$($word.Word)' Path: $($_["FileRef"])" -ForegroundColor Yellow;
$permissions = @()
$perm = Get-PnPProperty -ClientObject $_ -Property RoleAssignments
foreach ($role in $_.RoleAssignments) {
$loginName = Get-PnPProperty -ClientObject $role.Member -Property LoginName
$rolebindings = Get-PnPProperty -ClientObject $role -Property RoleDefinitionBindings
$permissions += "$($loginName) - $($rolebindings.Name)"
}
$permissions = $permissions | Out-String
if ($_ -eq $null) {
write-host "Error: 'Unable to pull file information'."
} else {
$size = Format-FileSize($_["File_x0020_Size"])
$results = New-Object PSObject -Property @{
FileName = $_["FileLeafRef"]
FileExtension = $_["File_x0020_Type"]
FileSize = $size
Path = $_["FileRef"]
Permissions = $permissions
Criteria = $word.Word
Created = $_["Created"]
Modified = $_["Modified"]
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
}
}
}
}
if ($siteParentOnly -eq $false) {
$subSites = Get-PnPSubWeb -Recurse
foreach ($site in $subSites) {
Connect-PnPOnline -Url $site.Url -UseWebLogin -WarningAction SilentlyContinue
$getSubDocLibs = Get-PnPList | where-object {$_.BaseTemplate -eq 101}
write-host "Searching: $($site.Url)" -ForegroundColor Green
foreach ($subDocLib in $getSubDocLibs) {
Get-PnPListItem -List $subDocLib -Fields "FileRef", "File_x0020_Type", "FileLeafRef", "File_x0020_Size", "Created", "Modified" -PageSize 1000 | Where { $_["FileLeafRef"] -like "*.*" } | foreach-object {
foreach ($word in $global:wordDirtySearch) {
$wordSearch = "(?i)\b$($word.Word)\b"
if (($_["FileLeafRef"] -match $wordSearch)) {
write-host "File found. " -ForegroundColor Red -nonewline; write-host "Under: '$($word.Word)' Path: $($_["FileRef"])" -ForegroundColor Yellow;
$permissions = @()
$perm = Get-PnPProperty -ClientObject $_ -Property RoleAssignments
foreach ($role in $_.RoleAssignments) {
$loginName = Get-PnPProperty -ClientObject $role.Member -Property LoginName
$rolebindings = Get-PnPProperty -ClientObject $role -Property RoleDefinitionBindings
$permissions += "$($loginName) - $($rolebindings.Name)"
}
$permissions = $permissions | Out-String
if ($_ -eq $null) {
write-host "Error: 'Unable to pull file information'."
} else {
$size = Format-FileSize($_["File_x0020_Size"])
$results = New-Object PSObject -Property @{
FileName = $_["FileLeafRef"]
FileExtension = $_["File_x0020_Type"]
FileSize = $size
Path = $_["FileRef"]
Permissions = $permissions
Criteria = $word.Word
Created = $_["Created"]
Modified = $_["Modified"]
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
}
}
}
}
}
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White;
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region SITE TOOLS FUNCTIONS OPTION "3"
function spoSiteGetCollectionAdmins {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$results = @()
$sitePath = read-host "`nENTER SITE COLLECTION URL"
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
Get-PnPSiteCollectionAdmin | foreach-object {
$results = New-Object PSObject -Property @{
Id = $_.Id
Title = $_.Title
Email = $_.Email
LoginName = $_.LoginName
IsSiteAdmin = $_IsSiteAdmin
IsShareByEmailGuestUser = $_.IsShareByEmailGuestUser
IsHiddenInUI = $_.IsHiddenInUI
PrincipalType = $_.PrincipalType
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region SITE TOOLS FUNCTIONS OPTION "4"
function spoSiteGetCollectionGroups {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE COLLECTION URL"
$results = @()
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
Get-PnPGroup | Where {$_.IsHiddenInUI -eq $false -and $_.LoginName -notlike "Limited Access*" -and $_.LoginName -notlike "SharingLinks*"} | Select-Object "Id", "Title", "LoginName", "OwnerTitle" | foreach-object {
$members = @()
Get-PnPGroupMember -Identity $_.Title | foreach-object {
$members += "$($_.Title)"
}
$members = $members | Out-String
$results = New-Object PSObject -Property @{
ID = $_.Id
GroupName = $_.Title
LoginName = $_.LoginName
OwnerTitle = $_.OwnerTitle
Members = $members
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region SITE TOOLS FUNCTIONS OPTION "5"
function spoSiteAddCollectionAdmin {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$results = @()
$userEmails = @()
do {
$userEmail = read-host "`nENTER USERS EMAIL OR 'D' FOR DONE"
if ($userEmail -ne "d") {
if (emailValidation -email $userEmail) {
$userEmails += $userEmail
} else {
write-host "`nNOT A VALID EMAIL ADDRESS" -ForegroundColor Red
}
}
} while ($userEmail -ne "d")
$sitePath = read-host "`nENTER SITE COLLECTION URL"
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
ForEach ($userEmail In $userEmails) {
Add-PnPSiteCollectionAdmin -Owners $userEmail
$results = New-Object PSObject -Property @{
AdminNew = $userEmail
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region SITE TOOLS FUNCTIONS OPTION "6"
function spoSiteDeleteCollectionAdmin {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$results = @()
$sitePath = read-host "`nENTER SITE COLLECTION URL"
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try{
$getAdmins = @()
Get-PnPSiteCollectionAdmin | foreach-object { $getAdmins += $_ }
do {
write-host "`nPLEASE SELECT AN ADMIN`n"
foreach ($admin in $getAdmins) {
write-host "`t$($getAdmins.IndexOf($admin)+1): PRESS $($getAdmins.IndexOf($admin)+1) for $($admin.Title)"
}
$adminChoice = read-host "PLEASE MAKE A SELECTION"
} while (-not($getAdmins[$adminChoice-1]))
Remove-PnPSiteCollectionAdmin -Owners $getAdmins[$adminChoice-1].Title
$results = New-Object PSObject -Property @{
AdminDeleted = $getAdmins[$adminChoice-1].Title
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#endregion
#region GROUP TOOLS FUNCTIONS
function showGroupTools {
write-host "`nGROUP TOOLS -- SELECT AN OPTION`n
`t1: PRESS '1': GROUP ADD 'EVERYONE' CONTAINER.
`tE: PRESS 'E' TO EXIT BACK TO THE MAIN MENU.`n
FOR HELP TYPE NUMBER AND ADD ? (E.G. 1?)`n"
}
#region GROUP TOOLS FUNCTIONS OPTION "1"
function spoGroupAddEveryone {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$results = @()
$siteGroupEveryone = "c:0(.s|true"
$siteGroupName = read-host "`nENTER GROUP NAME"
$sitePath = read-host "`nENTER SITE COLLECTION URL"
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
Try {
Add-PnPGroupMember -LoginName $siteGroupEveryone -Identity $siteGroupName
$results = New-Object PSObject -Property @{
Group = $siteGroupName
UserAdded = $siteGroupEveryone
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#endregion
#region USER TOOLS FUNCTIONS
function showUserTools {
write-host "`nUSER TOOLS -- SELECT AN OPTION`n
`t1: PRESS '1': USER DELETION.
`t2: PRESS '2': USER GROUP DELETION.
`tE: PRESS 'E' TO EXIT BACK TO THE MAIN MENU.`n
FOR HELP TYPE NUMBER AND ADD ? (E.G. 1?)`n"
}
#region USER TOOLS FUNCTIONS OPTION "1"
function spoUserDelete {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$results = @()
$userEmails = @()
do {
$userEmail = read-host "`nENTER USERS EMAIL OR 'D' FOR DONE"
if ($userEmail -ne "d") {
if (emailValidation -email $userEmail) {
$userEmails += $userEmail
} else {
write-host "`nNOT A VALID EMAIL ADDRESS" -ForegroundColor Red
}
}
} while ($userEmail -ne "d")
$sitePath = read-host "`nENTER SITE COLLECTION URL"
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
ForEach ($userEmail In $userEmails) {
$userInformation = Get-PnPUser | ? Email -eq $userEmail | foreach-object {
Remove-PnPUser -Identity $_.Title -Force
write-host "User Deleted: $($_.Title)" -ForegroundColor Yellow
$results = New-Object PSObject -Property @{
UserDeleted = $_.Title
UserEmail = $_.Email
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region USER TOOLS FUNCTIONS OPTION "2"
function spoUserDeleteGroups {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$results = @()
$userEmails = @()
do {
$userEmail = read-host "`nENTER USERS EMAIL OR 'D' FOR DONE"
if ($userEmail -ne "d") {
if (emailValidation -email $userEmail) {
$userEmails += $userEmail
} else {
write-host "`nNOT A VALID EMAIL ADDRESS" -ForegroundColor Red
}
}
} while ($userEmail -ne "d")
$sitePath = read-host "`nENTER SITE COLLECTION URL"
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
ForEach ($userEmail In $userEmails) {
$userInformation = Get-PnPUser | ? Email -eq $userEmail | foreach-object { $_ }
$userGroups = Get-PnPUser | ? Email -eq $userEmail | Select -ExpandProperty Groups | Where { ($_.Title -notmatch "Limited Access*") -and ($_.Title -notmatch "SharingLinks*") } | foreach-object {
write-host "Name: $userInformation.Title | Group Removed: " -ForegroundColor Yellow -NoNewline; write-host $($_.Title) -ForegroundColor Cyan
Remove-PnPGroupMember -LoginName $userEmail -Identity $_.Title
$results = New-Object PSObject -Property @{
UserDisplay = $userInformation.Title
UserEmail = $userEmail
UserGroup = $_.Title
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#endregion
#region LIST TOOLS FUNCTIONS
function showListTools {
write-host "`nCUSTOM LIST TOOLS -- SELECT AN OPTION`n
`t1: PRESS '1': LIST SHOW IN BROWSER.
`t2: PRESS '2': LIST HIDE FROM BROWSER.
`t3: PRESS '3': LIST DELETE ALL UNIQUE PERMISSIONS.
`t4: PRESS '4': LIST DELETE ALL ITEMS.
`tE: PRESS 'E' TO EXIT BACK TO THE MAIN MENU.`n
FOR HELP TYPE NUMBER AND ADD ? (E.G. 1?)`n"
}
#region LIST TOOLS FUNCTIONS OPTION "1"
function spoListShow {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE URL THAT LIST RESIDES ON"
$results = @()
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
$listsGet = @()
Get-PnPList | where-object { $_.Hidden -eq $true -and ($_.BaseTemplate -eq 100 -or $_.BaseTemplate -eq 101 -or $_.BaseTemplate -eq 102 -or $_.BaseTemplate -eq 103 -or $_.BaseTemplate -eq 104 -or $_.BaseTemplate -eq 105 -or $_.BaseTemplate -eq 106 -or $_.BaseTemplate -eq 107 -or $_.BaseTemplate -eq 108 -or $_.BaseTemplate -eq 109) } | foreach-object { $listsGet += $_ }
if ($listsGet.count) {
do {
write-host "`nPLEASE SELECT A LIST`n"
foreach ($list in $listsGet) {
write-host "`t$($listsGet.IndexOf($list)+1): PRESS $($listsGet.IndexOf($list)+1) for $($list.Title)"
}
$listChoice = read-host "`nPLEASE MAKE A SELECTION"
} while (-not($listsGet[$listChoice-1]))
Set-PnPList -Identity $listsGet[$listChoice-1].Title -Hidden $false
$results = New-Object PSObject -Property @{
ShowList = $listsGet[$listChoice-1].Title
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} else {
write-host "`nNO LISTS FOUND." -ForegroundColor Red
}
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region LIST TOOLS FUNCTIONS OPTION "2"
function spoListHide {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE URL THAT LIST RESIDES ON"
$results = @()
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
$listsGet = @()
Get-PnPList | where-object { $_.Hidden -eq $false } | foreach-object { $listsGet += $_ }
if ($listsGet.count) {
do {
write-host "`nPLEASE SELECT A LIST`n"
foreach ($list in $listsGet) {
write-host "`t$($listsGet.IndexOf($list)+1): PRESS $($listsGet.IndexOf($list)+1) for $($list.Title)"
}
$listChoice = read-host "`nPLEASE MAKE A SELECTION"
} while (-not($listsGet[$listChoice-1]))
Set-PnPList -Identity $listsGet[$listChoice-1].Title -Hidden $true
$results = New-Object PSObject -Property @{
HideList = $listsGet[$listChoice-1].Title
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} else {
write-host "`nNO LISTS FOUND." -ForegroundColor Red
}
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region LIST TOOLS FUNCTIONS OPTION "3"
function spoListDeleteAllUniquePermissions {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE URL THAT LIST RESIDES ON"
$results = @()
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
$listsGet = @()
Get-PnPList | where-object { $_.Hidden -eq $false } | foreach-object { $listsGet += $_ }
if ($listsGet.count) {
do {
write-host "`nPLEASE SELECT A LIST`n"
foreach ($list in $listsGet) {
write-host "`t$($listsGet.IndexOf($list)+1): PRESS $($listsGet.IndexOf($list)+1) for $($list.Title)"
}
$listChoice = read-host "`nPLEASE MAKE A SELECTION"
} while (-not($listsGet[$listChoice-1]))
$listItems = Get-PnPListItem -List $listsGet[$listChoice-1].Title -PageSize 500
ForEach($item in $listItems) {
$checkItemPermissions = Get-PnPProperty -ClientObject $item -Property "HasUniqueRoleAssignments"
If($checkItemPermissions) {
Set-PnPListItemPermission -List $listsGet[$listChoice-1].Title -Identity $item.Id -InheritPermissions
$results = New-Object PSObject -Property @{
ListName = $listsGet[$listChoice-1].Title
ItemID = $item.Id
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} else {
write-host "`nNO LISTS FOUND." -ForegroundColor Red
}
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#region LIST TOOLS FUNCTIONS OPTION "4"
function spoListDeleteAllItems {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE URL THAT LIST RESIDES ON"
$results = @()
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
$listsGet = @()
Get-PnPList | where-object { $_.Hidden -eq $false } | foreach-object { $listsGet += ($_) }
if ($listsGet.count) {
do {
write-host "`nPLEASE SELECT A LIST`n"
foreach ($list in $listsGet) {
write-host "`t$($listsGet.IndexOf($list)+1): PRESS $($listsGet.IndexOf($list)+1) for $($list.Title)"
}
$listChoice = read-host "`nPLEASE MAKE A SELECTION"
} while (-not($listsGet[$listChoice-1]))
$listItems = Get-PnPListItem -List $listsGet[$listChoice-1].Title -PageSize 500
$Batch = New-PnPBatch
ForEach($item in $listItems) {
Remove-PnPListItem -List $listsGet[$listChoice-1].Title -Identity $item.Id -Recycle -Batch $Batch
$results = New-Object PSObject -Property @{
ListName = $listsGet[$listChoice-1].Title
ItemDeletedID = $item.Id
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
Invoke-PnPBatch -Batch $Batch
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; } else { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "NO INFORMATION GENERATED" -ForegroundColor White; }
} else {
write-host "`nNO LISTS FOUND." -ForegroundColor Red
}
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
}
#endregion
#endregion
#region DOCUMENT TOOLS FUNCTIONS
function showDocumentTools {
write-host "`nDOCUMENT TOOLS -- SELECT AN OPTION`n
`t1: PRESS '1': DOCUMENT FOLDER UPLOAD.
`t2: PRESS '2': DOCUMENT SHARED LINKS REPORT.
`t3: PRESS '3': DOCUMENT REMOVE ALL SHARED LINKS..
`tE: PRESS 'E' TO EXIT BACK TO THE MAIN MENU.`n
FOR HELP TYPE NUMBER AND ADD ? (E.G. 1?)`n"
}
#region DOCUMENT TOOLS FUNCTIONS OPTION "1"
function spoDocumentFolderUpload {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$results = @()
$getDocumentLibraries = @()
$selectedLibraryFolder = ""
$localPath = read-host "ENTER LOCAL DIRECTORY LOCATION TO COPY"
if ((Get-Item $localPath) -is [System.IO.DirectoryInfo]) {
$sitePath = read-host "ENTER SITE URL THAT DOCUMENT LIBRARY RESIDES ON"
$sitePath = $sitePath.Trim(" ", "/")
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
Get-PnPList | where-object { $_.Hidden -eq $false -and $_.BaseTemplate -eq 101 -and $_.Title -ne "SiteCollectionDocuments" -and $_.Title -ne "Style Library" -and $_.Title -ne "FormServerTemplates" -and $_.Title -ne "Form Templates" } | foreach-object { $getDocumentLibraries += $_ }
do {
write-host "`nPLEASE SELECT A DOCUMENT LIBRARY`n"
foreach ($documentLibrary in $getDocumentLibraries) {
write-host "`t$($getDocumentLibraries.IndexOf($documentLibrary)+1): PRESS $($getDocumentLibraries.IndexOf($documentLibrary)+1) for $($documentLibrary.Title)"
}
$documentLibraryChoice = read-host "`nPLEASE MAKE A SELECTION"
} while (-not($getDocumentLibraries[$documentLibraryChoice-1]))
$selectedLibraryURLFolder = $getDocumentLibraries[$documentLibraryChoice-1].RootFolder.ServerRelativeUrl.replace($getDocumentLibraries[$documentLibraryChoice-1].ParentWebUrl,"")
do {
$selectedSubFolders = @()
Get-PnPFolderItem -FolderSiteRelativeUrl $selectedLibraryURLFolder -ItemType Folder | Where { $_.Name -ne "Forms" } | foreach-object { $selectedSubFolders += $_ }
if($selectedSubFolders.count) {
write-host "`nPLEASE SELECT A FOLDER TO COPY TO`n"
foreach ($child in $selectedSubFolders) {
write-host "$($selectedSubFolders.IndexOf($child)+1): PRESS $($selectedSubFolders.IndexOf($child)+1) for $($child.Name)"
}
write-host "S: PRESS S to Select Current Folder"
$folderChoice = read-host "`nPLEASE MAKE A SELECTION"
} else { $folderChoice = "S" }
if($folderChoice -ne "S") {
if(-not($selectedSubFolders[$folderChoice-1])) {
} else {
$selectedLibraryURLFolder += "/$($selectedSubFolders[$folderChoice-1].Name)"
}
} else {
$selectedLibraryFolder = $selectedLibraryURLFolder.Trim(" ", "/")
}
} while ($selectedLibraryFolder -eq "")
$Confirm = read-host "WOULD YOU LIKE TO UPLOAD DOCUMENTS TO THIS FOLDER: $($selectedLibraryFolder)? [Y] Yes [N] No"
if($Confirm -match "[yY]") {
write-host "`nProcessing Folder: $($localPath)" -f Yellow
Resolve-PnPFolder -SiteRelativePath $selectedLibraryFolder | out-null
$files = Get-ChildItem -Path $localPath -File
foreach ($file in $files) {
Add-PnPFile -Path "$($file.Directory)\$($file.Name)" -Folder $selectedLibraryFolder -Values @{"Title" = $($file.Name)} | out-null
write-host "`tUploaded File: $($file.FullName)" -f Green
$results = New-Object PSObject -Property @{
Type = "File"
OriginalLocation = $file.FullName
NewLocation = "$($sitePath)/$selectedLibraryFolder/$($file.Name)"
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
Get-ChildItem -Path $localPath -Recurse -Directory | foreach-object {
$folderToUpload = ($selectedLibraryFolder+$_.FullName.Replace($localPath,"")).Replace("\","/")
write-host "Processing Folder: $($_.FullName)" -ForegroundColor Yellow
Resolve-PnPFolder -SiteRelativePath $folderToUpload | out-null
$results = New-Object PSObject -Property @{
Type = "Folder"
OriginalLocation = $_.FullName
NewLocation = "$($sitePath)/$($folderToUpload)"
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
$files = Get-ChildItem -Path $_.FullName -File
foreach ($file in $files) {
Add-PnPFile -Path "$($file.Directory)\$($file.Name)" -Folder $folderToUpload -Values @{"Title" = $($file.Name)} | out-null
write-host "`tUploaded File: $($file.FullName)" -ForegroundColor Green
$results = New-Object PSObject -Property @{
Type = "File"
OriginalLocation = $file.FullName
NewLocation = "$($sitePath)/$($folderToUpload)/$($file.Name)"
}
reportCreate -reportPath "$($setupReportPath)\$($reportName)" -reportData $results
}
}
}
write-host "`nCompleted: " -ForegroundColor DarkYellow -nonewline; write-host "$(get-date -format yyyy/MM/dd-HH:mm:ss)" -ForegroundColor White;
if (test-path "$($reportPath)\$($reportName)") { write-host "Report Saved: " -ForegroundColor DarkYellow -nonewline; write-host "$($reportPath)\$($reportName)" -ForegroundColor White; }
} Catch {
Write-host "`nAN ERROR HAS OCCURRED" -ForegroundColor Red
}
Disconnect-PnPOnline
} else {
write-host "`nPATH SUPPLIED WAS NOT A FOLDER! PLEASE CHECK YOUR LOCAL DIRECTORY PATH AND TRY AGAIN!" -ForegroundColor Red
}
}
#endregion
#region DOCUMENT TOOLS FUNCTIONS OPTION "2"
function spoDocumentSharedLinks {
param([Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportPath,
[Parameter(Mandatory)][ValidateNotNullOrEmpty()][string]$reportName)
$sitePath = read-host "`nENTER SITE URL THAT LIST RESIDES ON"
$results = @()
Connect-PnPOnline -Url $sitePath -UseWebLogin -WarningAction SilentlyContinue
try {
$listsGet = @()
Get-PnPList | where-object { $_.Hidden -eq $false -and $_.BaseTemplate -eq 101 } | foreach-object { $listsGet += $_ }
if ($listsGet.count) {
do {
write-host "`nPLEASE SELECT A LIST`n"
foreach ($list in $listsGet) {
write-host "`t$($listsGet.IndexOf($list)+1): PRESS $($listsGet.IndexOf($list)+1) for $($list.Title)"
}
$listChoice = read-host "`nPLEASE MAKE A SELECTION"
} while (-not($listsGet[$listChoice-1]))
$listItems = Get-PnPListItem -List $listsGet[$listChoice-1].Title -PageSize 500
ForEach($item in $listItems) {
$checkItemPermissions = Get-PnPProperty -ClientObject $item -Property "HasUniqueRoleAssignments"
If($checkItemPermissions) {
$checkRoleAssignments = Get-PnPProperty -ClientObject $Item -Property RoleAssignments
ForEach($role in $checkRoleAssignments) {
$getMembers = Get-PnPProperty -ClientObject $role -Property RoleDefinitionBindings, Member
$getUsers = Get-PnPProperty -ClientObject $role -Property Users -ErrorAction SilentlyContinue
If ($role.Member.Title -like "SharingLinks*") {