Forum Discussion
Sheila2566
Jul 11, 2024Copper Contributor
PS Script for SharePoint Online to Pull Filename w Extension, Uploaded during a Time Period
Pretty much what the subject has. I need PS Script for SharePoint Online to Pull Filename with Extension Uploaded during a Designated Time Period on a specific site. I have tried to use Purview and Sentinel. Our Purview does not work at all and Microsoft has been no help. And there is nothing for File Size in Sentinel, otherwise I have what I need, but I definitely need the file sizes of each of the files.
1 Reply
Sort By
- sdtslmnCopper Contributor
here is the powershell script you can use
# Install the SharePoint Online Management Shell module if you haven't already Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Scope CurrentUser # Connect to SharePoint Online $adminUPN = "your_admin_email@your_domain.com" $siteUrl = "https://your_tenant.sharepoint.com/sites/your_site_name" Connect-SPOService -Url $siteUrl -Credential (Get-Credential -UserName $adminUPN) # Define time range $startTime = Get-Date "2024-07-20T00:00:00Z" # Example start time (adjust as needed) $endTime = Get-Date "2024-07-25T23:59:59Z" # Example end time (adjust as needed) # Get all files in the site within the time range $allFiles = Get-PnPListItem -List Documents -PageSize 500 -Fields Title, TimeLastModified, File_x0020_Size $allFiles = $allFiles | Where-Object { $_.TimeLastModified -ge $startTime -and $_.TimeLastModified -le $endTime } # Create a custom object to hold file information $fileData = @() foreach ($file in $allFiles) { $fileInfo = [PSCustomObject]@{ FileName = $file.FieldValues.Title LastModified = $file.FieldValues.TimeLastModified FileSizeInBytes = $file.FieldValues.File_x0020_Size FileSizeMB = "{0:N2}" -f ($file.FieldValues.File_x0020_Size / 1MB) # Convert to MB, format to 2 decimal places } $fileData += $fileInfo } # Display the results in a table $fileData | Format-Table -AutoSize # Disconnect from SharePoint Online Disconnect-SPOService