Hi @mm ,
Please try following PowerShell :
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Config Parameters
$SiteURL= "https://tenant.sharepoint.com/sites/sitename"
$ListName = "libraryname"
$CSVPath = "C:\Temp\DocumentsInventory.csv"
#Get Credentials to connect
$Cred = Get-Credential
Try {
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Get the Document Library
$List =$Ctx.Web.Lists.GetByTitle($ListName)
#Define CAML Query to Get All Files
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "@<View Scope='RecursiveAll'>
<Query>
<Where>
<Eq>
<FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value>
</Eq>
</Where>
</Query>
</View>"
#powershell sharepoint online list all documents
$ListItems = $List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$DataCollection = @()
#Iterate through each document in the library
ForEach($ListItem in $ListItems)
{
#Collect data
$Data = New-Object PSObject -Property ([Ordered] @{
FileName = $ListItem.FieldValues["FileLeafRef"]
RelativeURL = $ListItem.FieldValues["FileRef"]
CreatedBy = $ListItem.FieldValues["Created_x0020_By"]
CreatedOn = $ListItem.FieldValues["Created"]
ModifiedBy = $ListItem.FieldValues["Modified_x0020_By"]
ModifiedOn = $ListItem.FieldValues["Modified"]
FileSize = $ListItem.FieldValues["File_x0020_Size"]
})
$DataCollection += $Data
}
$DataCollection
#Export Documents data to CSV
$DataCollection | Export-Csv -Path $CSVPath -Force -NoTypeInformation
Write-host -f Green "Documents Data Exported to CSV!"
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
After we run the PowerShell above, we will find csv file in C:\Temp\ , created/modified date and file size information are in it.
Note: We can only get the date when the file was uploaded for the first time (Created) and the last modified date, that is, the time when the user modified or uploaded the file in SharePoint Online (Modified).
Reference:
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
---------------------------------------------------------------------------------------------------------------------------------------------------------------
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.