How to set RecyclebinRetentionPeriod settings for SharePoint Web Application (PowerShell)

Introduction

This script could be used to set RecyclebinRetentionPeriod settings for SharePoint Web Application.

Scenarios

Sometimes, SharePoint admin need to set RecyclebinRetentionPeriod settings.

Script

This script contains one advanced function, Set-OSCRecycleBinRetentionPeriod. You can use this script in following ways:
Method 1:
  1. Download the script and open the script file with Notepad or any other script editors.
  2. Scroll down to the end of the script file, and then add the example command which you want to run.
  3. Save the file then run the script in PowerShell.
Method 2:
  1. Rename scriptname.ps1 to scriptname.psm1 (PowerShell Module file)
  2. Run Import-Module cmdlet to import this module file.
    Import-Module filepath\scriptname.psm1

Examples

Example 1: Set RecycleBinRetentionPeriod time to 150 days on WebApplication http://win-lfseeatt8jr/ .
Command: Set-OSCRecycleBinRetentionPeriod -WebApplication "http://win-lfseeatt8jr/" -Day 150
Screenshot:
 
Here are some code snippets for your references.
PowerShell
Edit|Remove
#Get current RecycleBinRetentionPeriod 
$Currentday = $webapp.RecycleBinRetentionPeriod 
#Get user's choice 
$result = GetChoice $Currentday $Day 
#If 'yes', execute the script 
if($result -eq  0 ) 
{ 
    $webapp.RecycleBinRetentionPeriod = $Day 
    $webapp.update() 
    write-host "Set RecycleBinRetentionPeriod to $Day successfully. "} 
Else 
{ 
    write-warning "Action cancelled by user."}

Prerequisite

PowerShell
Windows Server 2008R2 or later version