Configure SharePoint Recycle Bin Settings - PowerShell

ALVES Ricardo 106 Reputation points
2022-12-13T14:54:24.783+00:00

Hello Guys,

On SharePoint once We delete an item It goes to RecycleBin (first-second stage)
The retention period is 93 days after deletion.

Anyone knows how could I change the number of days from 93 to 30 days in Powershell for each site?

Thank you so much

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,993 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,627 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Xyza Xue_MSFT 28,226 Reputation points Microsoft Vendor
    2022-12-14T02:26:59.2+00:00

    Hi @ALVES Ricardo ,
    To clarify, in SharePoint server
    Site Recycle Bin (First-Stage) = 30 days
    270937-image.png
    Reference: https://learn.microsoft.com/en-us/sharepoint/sites/delete-and-restore-site-collections
    If you want to change the number of days, just change the configuration of the SharePoint web application recycle bin and you have changed all the sites.
    Powershell code:

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
       
    #Get the Web Application  
    $WebApp = Get-SpWebApplication "http://sp16"  
       
    #*** Set Recycle bin Options ***  
    #Enable Recycle bin  
    $WebApp.RecycleBinEnabled = $true  
       
    #Set Retention Period to 30 days  
    $WebApp.RecycleBinRetentionPeriod = 30  
    #To Turnoff Recycle bin Retention, use: $WebApp.RecycleBinCleanUpEnabled=$false  
       
    #Set Second Stage Recycle bin Quota %  
    $WebApp.SecondStageRecycleBinQuota = 30  
    #To turn OFF Second Stage recycle bin, use: $WebApp.SecondStageRecycleBinQuota = 0  
       
    #Apply the changes  
    $WebApp.Update()  
       
    Write-Host "Recycle bin Settings Updated!"  
    

    270238-image.png

    You can directly change the number of days or view the powershell running results through the following path.
    270293-image.png
    Reference: https://support.microsoft.com/en-us/office/configure-sharepoint-recycle-bin-settings-427bf749-cfb4-4b5a-80aa-3bd2b24ef4f0#:~:text=Choose%20the%20site%20you%20want,under%20Manage%20on%20the%20ribbon.&text=Under%20Recycle%20Bin%20Status%2C%20select,turned%20on%20or%20turned%20off.
    270301-image.png


    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. ALVES Ricardo 106 Reputation points
    2022-12-15T14:28:25.263+00:00

    Hello,
    Thank you for you response.

    I've been reading about it and it just works if I connect with SharePoint on-premises


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.