OneDrive Missing Files and Folders

Roger Roger 4,951 Reputation points

Hi All

i have a user who reported that some of the folders/files in his OneDrive are missing. I want to export all the files and folders names from users onedrive to an excel sheeting using PowerShell. I am able to export the contents of users OneDrive recycle bin using the below syntax not sure how to export to OneDrive files and folders to csv file.

$SiteURL = ""
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
Get-PnPRecycleBinItem | Export-Csv C:\temp\output.csv

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,153 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,041 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,761 questions
0 comments No comments
{count} votes

Accepted answer
  1. Allen Xu_MSFT 13,756 Reputation points

    Hi @Roger Roger

    I got all files and folders names in OneDrive My files library using the following PnP PowerShell Commands.

    #Set Variables  
    $SiteURL= ""  
    #Connect to PnP Online  
    Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)  
    #Get All Files from the document library - In batches of 500  
    $ListItems = Get-PnPListItem -List $ListName -PageSize 500  
    #Loop through all documents  
    ForEach($Item in $ListItems)  
        #Collect Documents Data  
        $DocumentsData += New-Object PSObject -Property @{  
        FileName = $Item.FieldValues['FileLeafRef']  
        FileURL = $Item.FieldValues['FileRef']  
    $DocumentsData | Export-Csv C:\temp\output.csv  

    Test on my end.

    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.

0 additional answers

Sort by: Most helpful