OneDrive Missing Files and Folders

Roger Roger 4,951 Reputation points
2021-05-25T15:27:14.49+00:00

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 = "https://contoso-my.sharepoint.com/personal/John_A_contoso_com/_layouts/15/onedrive.aspx"
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
Get-PnPRecycleBinItem | Export-Csv C:\temp\output.csv

SharePoint
SharePoint
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
    2021-05-26T07:09:24.847+00:00

    Hi @Roger Roger

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

    #Set Variables  
    $SiteURL= "https://contoso-my.sharepoint.com/personal/allenx_contoso_onmicrosoft_com"  
    $ListName="Documents"  
       
    #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  
    $DocumentsData=@()  
    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.
    99747-1.png


    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