Exporting OneDrive of users with no license to local PC?

EnterpriseArchitect 5,136 Reputation points
2023-03-08T14:59:10.1633333+00:00

How can I export or download the contents of the OneDrive account for the user whose licence was just revoked using PowerShell or any other freeware tool?

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,298 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
980 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,291 questions
OneDrive Management
OneDrive Management
OneDrive: A Microsoft file hosting and synchronization service.Management: The act or process of organizing, handling, directing or controlling something.
1,198 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,899 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 33,641 Reputation points Microsoft Vendor
    2023-03-09T01:53:47.48+00:00

    Hi @EnterpriseArchitect ,

    To use OneDrive for Business, the user should have Office 365 Business Essentials license at least.

    To get to OneDrive for Business, sign in to Office 365 or your SharePoint site->Click the app launcher at the top of the page-> click OneDrive.

    You could check the license of the user in Office 365 admin center.

    Go to Office 365 admin center->choose Users -> Active users-> select the box next to the name of the user-> check the Product licenses row.

    More references:

    What is OneDrive for Business.

    https://support.office.com/en-us/article/What-is-OneDrive-for-Business-187f90af-056f-47c0-9656-cc0ddca7fdc2

    You can use an account with permission to the onedrive by following script

    #Parameters
    $OneDriveSiteURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"
    $DownloadPath ="C:\Temp\OneDrive"
     
    Try {
        #Connect to OneDrive site
        Connect-PnPOnline $OneDriveSiteURL -Interactive
        $Web = Get-PnPWeb
     
        #Get the "Documents" library where all OneDrive files are stored
        $List = Get-PnPList -Identity "Documents"
      
        #Get all Items from the Library - with progress bar
        $global:counter = 0
        $ListItems = Get-PnPListItem -List $List -PageSize 500 -Fields ID -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete `
                    ($global:Counter / ($List.ItemCount) * 100) -Activity "Getting Items from OneDrive:" -Status "Processing Items $global:Counter to $($List.ItemCount)";}
        Write-Progress -Activity "Completed Retrieving Files and Folders from OneDrive!" -Completed
      
        #Get all Subfolders of the library
        $SubFolders = $ListItems | Where {$_.FileSystemObjectType -eq "Folder" -and $_.FieldValues.FileLeafRef -ne "Forms"}
        $SubFolders | ForEach-Object {
            #Ensure All Folders in the Local Path
            $LocalFolder = $DownloadPath + ($_.FieldValues.FileRef.Substring($Web.ServerRelativeUrl.Length)) -replace "/","\"
            #Create Local Folder, if it doesn't exist
            If (!(Test-Path -Path $LocalFolder)) {
                    New-Item -ItemType Directory -Path $LocalFolder | Out-Null
            }
            Write-host -f Yellow "Ensured Folder '$LocalFolder'"
        }
      
        #Get all Files from the folder
        $FilesColl =  $ListItems | Where {$_.FileSystemObjectType -eq "File"}
      
        #Iterate through each file and download
        $FilesColl | ForEach-Object {
            $FileDownloadPath = ($DownloadPath + ($_.FieldValues.FileRef.Substring($Web.ServerRelativeUrl.Length)) -replace "/","\").Replace($_.FieldValues.FileLeafRef,'')
            Get-PnPFile -ServerRelativeUrl $_.FieldValues.FileRef -Path $FileDownloadPath -FileName $_.FieldValues.FileLeafRef -AsFile -force
            Write-host -f Green "Downloaded File from '$($_.FieldValues.FileRef)'"
        }
    }
    Catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.