PowerShell command to bulk restore deleted files from sharepoint recycle bin

IniobongNkanga-8038 631 Reputation points
2024-08-31T14:00:01.47+00:00

Hello

Please i need your help on this issue.

There are thousands of files I need to restore from a site's recycle bin. Is there a faster way to bulk restore them using PowerShell than using the web interface.

When I run PowerShell as an administrator and use the command "Connect-SPOService -Url ..." I get an error saying `Connect-SPOService' is not recognized as the name of a cmdlet, function, script file, or operable program.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,972 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ling Zhou_MSFT 17,060 Reputation points Microsoft Vendor
    2024-09-02T02:22:10.6666667+00:00

    Hi @IniobongNkanga-8038,

    Thank you for posting in this community.

    The error “Connect-SPOService is not recognized as the name of a cmdlet” occurs when the SharePoint Online Management Shell module is not installed or loaded in the current PowerShell session. To resolve this error, follow these steps:

    Option 1: Download and Install SharePoint Online Management Shell

    You can download and install SharePoint Online Management Shell to your client machine from SharePoint Online Management Shell.

    User's image

    If it’s already installed, try uninstalling and then re-installing.

    Option 2: Install SharePoint Online PowerShell Module

    Double-check if the SharePoint Online PowerShell Module is installed by:

    Get-Module -ListAvailable -Name Microsoft.Online.SharePoint.PowerShell | Select Name,Version
    

    You can install the SharePoint Online PowerShell Module with the following:

    Install-Module Microsoft.Online.SharePoint.PowerShell
    

    For uninstallation, use:

    Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions -Force
    

    This will install necessary assemblies (.dll files) to the path: C:\Program Files\WindowsPowerShell\Modules\Microsoft.Online.SharePoint.PowerShell<Build-Number>

    Other Workarounds:

    Although we don’t have to explicitly load the module in PowerShell with “Import-Module Microsoft.Online.SharePoint.Powershell”, give it a try to expose any potential issues.

    If you are trying to connect to the SharePoint site from PowerShell through a proxy server, the Connect-SPOService cmdlet connections fail! You have to use the following method to connect to SPO Service:

    #Get Credentials to connect
    $cred = Get-Credential
    [System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred
     
    #Connect to SharePoint Online Administration Center
    Connect-SPOService -Url "https://<Tenant-admin>.sharepoint.com" -Credential $cred
    

    In another situation, I had to delete all different versions of SharePoint Online client Assemblies from the Global Assembly Cache (GAC) and then install the SharePoint Online PowerShell Module:

    1. Navigate to “C:\Windows\Microsoft.NET\assembly\GAC_MSIL”
    2. Select all folders starting with the name “Microsoft.SharePoint.Client” and delete them all!
    3. Finally, Install the PowerShell Module for SharePoint Online: Install-Module Microsoft.Online.SharePoint.PowerShell -force

    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.


  2. Alvaro Avila 80 Reputation points
    2024-09-09T13:55:23.87+00:00

    Hi Iniobong,

    It seems the SPO module for PowerShell is not installed on your device. Though SPO module doesn't have any command that I am aware for bulk restoration.

    PnP could help you with that, this sample script might help you. I didn't use it myself though; Restore large amount of items from SharePoint Recycle bin in bulk | PnP Samples

    Additionally, this is a free and open-source app that can help you: NovaPoint

    This is the doc about restoration of recycle bin: Restore items from the recycle bin

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.