question

RogerRoger-2394 avatar image
0 Votes"
RogerRoger-2394 asked AllenXu-MSFT commented

OneDrive Missing Files and Folders

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

office-sharepoint-onlineoffice-exchange-online-itprooffice-sharepoint-server-administration
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

AllenXu-MSFT avatar image
0 Votes"
AllenXu-MSFT answered AllenXu-MSFT commented

Hi @RogerRoger-2394

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.


1.png (36.3 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@RogerRoger-2394 ,

Is there any update on this thread? I'm looking forward to your reply :-)

0 Votes 0 ·

@RogerRoger-2394 ,

If an answer is helpful to you, don't forget to accept it as answer. It will be beneficial to others in this forum who has the same question as yours.

0 Votes 0 ·