Skip to main content

Enable AD Recycle Bin

Summary​

This document describes how to enable the Active Directory (AD) Recycle Bin on AD Infrastructure Masters.

Dependencies​

Create Script​

To implement this script, please create a new "PowerShell" style script in the system.

Image 1
Image 2

Name: Enable AD Recycle Bin
Description: This task enables AD recycle on Windows Infrastructure Masters
Category: Custom
Image 3

Script​

Row 1 Function: PowerShell Script​

Image

Paste in the following PowerShell script and set the expected time of script execution to 900 seconds.

PowerShell Script 1

Image

Step 2 Logic: If/Then​

  • Add a new If/Then logic from the Add Logic dropdown menu.

Image

ROW 2a Condition: Output Contains​

  • Type Outdated in the Value box.

Image

ROW 2b Function: Set Custom Field​

Add a new row in the If Section by clicking the Add Row button.

  • Search and select the Set Custom Field function.

Image

  • Search and select the AD Recycle Bin Custom Field.
  • Type Outdated PS version in the Value box and click the Save button.

Image

ROW 2c Function: Script Exit​

  • Add a new row in the If Section by clicking the Add Row button.
  • Search and select the Script Exit function.
  • Input the following:
The AD Recycle Bin failed to be enabled on the DC server as the PowerShell version is outdated. Minimum version required is above 3.0 and the current version is %output%

Image
Image

ROW 3 Function: PowerShell Script​

Image

Paste in the following PowerShell script and set the expected time of script execution to 900 seconds.

PowerShell Script 2

Image

ROW 4 Function: PowerShell Script​

Image

Paste in the following PowerShell script and set the expected time of script execution to 900 seconds.

PowerShell Script 3

Image

Step 5 Logic: If/Then​

  • Add a new If/Then logic from the Add Logic dropdown menu.

Image

ROW 5a Condition: Output Contains​

  • Type Minimum criteria for AD Recycle Bin enable in the Value box.

Image

Row 5b Function: Set Custom Field​

Add another row by selecting the ADD ROW button in the If section of the If/Then section.

  • Search and select the Set Custom Field function.

Image

  • Search and select the AD Recycle Bin Custom Field.
  • Type Does not meet minimum criteria in the Value box and click the Save button.

Image

ROW 5c Function: Script Exit​

  • Add a new row in the If Section by clicking the Add Row button.
  • Search and select the Script Exit function.
  • Input the following:
The AD Recycle Bin failed to be enabled on the DC server. The DomainMode or ForestMode is not eligible for the AD Recycle Bin to be enabled.

Logs:

%output%

Image
Image

ROW 6 Function: PowerShell Script​

Image

Paste in the following PowerShell script and set the expected time of script execution to 900 seconds.

PowerShell Script 4

Image

Step 7 Logic: If/Then/Else​

  • Add a new If/Then/Else logic from the Add Logic dropdown menu.

Image

ROW 7a Condition: Output Contains​

  • Type Failed to enable in the Value box.

Image

Step 7b Logic: If/Then​

Add a new If/Then logic from the Add Logic dropdown menu inside the IF section.

Image

Row 7b(i) Condition: Custom Field Does Not Contain​

  • Select Custom field from the dropdown.
  • Select AD Recycle Bin custom field from the dropdown.
  • Select Does Not Contain from the dropdown.
  • Type Does not meet minimum criteria into the value.

Image

Select ADD CONDITION in the Custom field section and add another condition.

  • Select Custom field from the dropdown.
  • Select AD Recycle Bin custom field from the dropdown.
  • Select Does Not Contain from the dropdown.
  • Type Outdated PS version into the value.

Image

Select ADD CONDITION in the Custom field section and add another condition.

  • Select Custom field from the dropdown.
  • Select AD Recycle Bin custom field from the dropdown.
  • Select Does Not Contain from the dropdown.
  • Type Enabled into the value.

Image

Select ADD CONDITION in the Custom field section and add another condition.

  • Select Custom field from the dropdown.
  • Select AD Recycle Bin custom field from the dropdown.
  • Select Does Not Contain from the dropdown.
  • Type failed more than 3 times into the value.

The whole custom field should look like this.

Image

Row 7b(ii) Condition: Set Pre-defined Variable​

Add another row by selecting the ADD ROW button in the IF section of the internal If/Then section.

  • Select Set Pre-Defined Variable function.

Image

  • Select Custom Field.
  • Input AD_RecycleBin_Result as the variable name.
  • Select AD Recycle Bin custom field from the dropdown.
  • Click Save.

Image

Row 7b(iii) Function: PowerShell Script​

Add another row by selecting the ADD ROW button in the IF section of the internal If/Then section.

  • Select PowerShell Script function.

Image

Paste in the following PowerShell script and set the expected time of script execution to 900 seconds.

PowerShell Script 5

Image

Row 7b(iv) Function: Set Custom Field​

Add another row by selecting the ADD ROW button in the IF section of the internal If/Then section.

  • Search and select the Set Custom Field function.

Image

  • Search and select the AD Recycle Bin Custom Field.
  • Type %Output% in the Value box and click the Save button.

Image

Row 7b(v) Function: Script Exit​

Add another row by selecting the ADD ROW button in the Else section of the internal If/Then section.

  • Search and select the Script Exit function.
  • Input the following:
Script failed to enable AD Recycle Bin on the DC server.

Logs:

%output%

Image
Image

Row 7c Function: Set Custom Field​

Add another row by selecting the ADD ROW button in the Else part of the If/Then/Else section.

  • Search and select the Set Custom Field function.

Image

  • Search and select the AD Recycle Bin Custom Field.
  • Type Enabled in the Value box and click the Save button.

Image

The final task should look like the screenshot below.

Image
Image

Script Deployment​

This task must be scheduled on the Infrastructure Master - Without Recycle Bin group for auto deployment. The script can also be run manually if required.

Go to Automations > Tasks.
Search for Enable AD Recycle Bin.
Then click on Schedule and provide the necessary parameters for script completion.

Image

Output​

  • Script log

Changelog​

2025-04-10​

  • Initial version of the document