About Sharepoint Online

JaixuSanzhi 25 Reputation points

I want to ask If there is any possible way for the following

  1. While moving file fromSPO to OneDrive the file also transfer to SPO recycle bin so i want to transfer file without
    Transfering it to SPO recycle bin
  2. If there is no way for the 1 the can i just delete the moved file from SPO recycle bin using powershell or something
A Microsoft file hosting and synchronization service.
732 questions
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,210 questions
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
1,867 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,011 Reputation points

    Hello JaixuSanzhi,

    Thank you for your question and for reaching out with your question today.

    There is no direct built-in method in SharePoint Online to move a file from SharePoint Online (SPO) to OneDrive without sending it to the SharePoint Online recycle bin first. When you move a file from one location to another, SharePoint follows its normal process, which involves placing the file in the recycle bin before moving it to the new location.

    If you want to achieve the desired behavior, you would need to consider alternative approaches. One possible approach is to use a combination of PowerShell and the SharePoint Online Management Shell to automate the process. Here's an outline of the steps you can follow:

    1. Use PowerShell to copy the file from SharePoint to the destination location in OneDrive.
    2. After the file has been successfully copied to OneDrive, use PowerShell to delete the original file from SharePoint Online (to bypass the recycle bin).

    Here's a basic PowerShell script outline for this process:

    # Install SharePoint Online Management Shell if not already installed
    # Run this command in PowerShell:
    # Install-Module -Name SharePointPnPPowerShellOnline -Force
    # Connect to SharePoint Online
    Connect-PnPOnline -Url "https://your-domain.sharepoint.com/sites/YourSite"
    # Define the source and destination URLs
    $sourceFileUrl = "/sites/YourSite/Shared Documents/Folder/YourFile.docx"
    $destinationUrl = "https://your-domain-my.sharepoint.com/personal/yourname_domain_com/Documents/Folder/YourFile.docx"
    # Copy the file from SharePoint to OneDrive
    Copy-PnPFile -SourceUrl $sourceFileUrl -TargetUrl $destinationUrl
    # Delete the original file from SharePoint (to bypass the recycle bin)
    Remove-PnPFile -ServerRelativeUrl $sourceFileUrl -RecycleBinHandling None

    Please note that PowerShell scripts can have significant consequences, so it's essential to thoroughly test this script in a non-production environment before using it on important files. Additionally, Microsoft may update SharePoint Online and its PowerShell modules beyond my knowledge cutoff date, so it's a good idea to check the latest documentation and resources for any changes or improvements related to SharePoint Online and PowerShell.

    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.

    If the reply was helpful, please don’t forget to upvote or accept as answer.

    Best regards.

    0 comments No comments

  2. Zehui Yao_MSFT 5,811 Reputation points

    Hi JaixuSanzhi, it is a pleasure to be able to help you.

    Since it is a default behavior, while moving file from SharePoint Online to OneDrive the file also transfer to recycle bin.

    You can also delete the moved file from recycle bin using below powershell:

    #Load SharePoint Online 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"
    ##Variables for Processing
    $SiteUrl = "https://crescent.sharepoint.com/sites/Sales/"
    #Get the password to connect
    $Password = Read-host -assecurestring "Enter Password for $UserName"
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Password)
    Try {   
        #Setup the context
        $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
        $Context.Credentials = $Credentials
        #Get the recycle bin
        $Site = $Context.Site
        $RecycleBinItems = $Site.RecycleBin
        Write-Host "Total Number of Items found Recycle Bin:" $RecycleBinItems.Count
        #sharepoint online powershell empty recycle bin
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red

    Hope this helps.

    Best Wishes.

    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.