Connect-PnPOnline -Url "https://m365x141782.sharepoint.com/sites/Mark8ProjectTeam"
Get-PnPList | Where-Object {$_.BaseTemplate -eq 101}
#Connect to the targeted site
Connect-PnPOnline -Url "https://m365x141782.sharepoint.com/sites/Mark8ProjectTeam"
#Declare variables
$results = @()
$allLibs = Get-PnPList | Where-Object {$_.BaseTemplate -eq 101}
foreach ($lib in $allLibs) {
#Store all docs in a variable
$allItems = Get-PnPListItem -List $lib.Title
foreach($item in $allItems){
$results += [PSCustomObject][ordered]@{
FileName = $item["FileLeafRef"]
CreatedBy = $item.FieldValues.Author.LookupValue
CreatedDate = [DateTime]$item["Created_x0020_Date"]
FilePath = $item["FileRef"]
}
}
}
$results
#Connect to SPO Site
Connect-PnPOnline -Url "https://m365x141782.sharepoint.com/sites/Mark8ProjectTeam"
#Store in variable all the document libraries in the site
$docLibrary = Get-PnPList | Where-Object { $_.BaseTemplate -eq 101 }
foreach ($docLib in $docLibrary) {
#Get list of all folders in the document library
$AllItems = Get-PnPListItem -List $docLib -Fields "SMTotalFileStreamSize"
#Loop through each files/folders in the document library for files >50Mb
foreach ($item in $allItems) {
if ((([int]$item["SMTotalFileStreamSize"]) -ge 50000000) -and ($item["FileLeafRef"] -like "*.*")) {
Write-Host "File found:" $item["FileLeafRef"] -ForegroundColor Yellow
[PSCustomObject]@{
FileName = $item["FileLeafRef"]
FilePath = $item["FileRef"]
SizeInMB = ($item["SMTotalFileStreamSize"] / 1MB).ToString("N")
LastModifiedBy = $item.FieldValues.Editor.LookupValue
EditorEmail = $item.FieldValues.Editor.Email
LastModifiedDate = [DateTime]$item["Modified"]
}
}
}
}
#Connect to SPO admin center
Connect-PnPOnline -Url https://m365x141782-admin.sharepoint.com
#Import sites from .csv
$mySites = Import-Csv -Path '<YOUR_FILE_PATH>'
#Create all for each site
foreach ($site in $mySites) {
#Connect to each site
Write-Host "Connecting to $($site.SiteUrl)" -ForegroundColor Green
Connect-PnPOnline -Url $site.SiteUrl
#Create the NEW permission level (clone the 'READ' default permissions)
$PermToClone = Get-PnPRoleDefinition -Identity "Read"
$addPnPRoleDefinitionSplat = @{
Include = 'ManagePersonalViews', 'UpdatePersonalWebParts', 'AddDelPrivateWebParts'
Description = "Copy of Read + Personal Permissions"
RoleName = "myCustomPermLevel"
Clone = $PermToClone
}
Add-PnPRoleDefinition @addPnPRoleDefinitionSplat
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.