PowerShell Enable AD Recycle Bin

  • Welcome to ITBible, we're your #1 resource for enterprise or homelab IT problems (or just a place to show off your stuff).
This was quick and dirty / probably needs some more work I'll add it to GitHub later.

PowerShell:
Import-Module ActiveDirectory

if ((Get-ADOptionalFeature -Identity 'Recycle Bin Feature').EnabledScopes)
{
    Write-Host "AD Recycle Bin Enabled"
}
else
{
    try
    {
        $domain = Get-WmiObject -Namespace Root\CIMV2 -Class Win32_ComputerSystem | select -ExpandProperty Domain
        Enable-ADOptionalFeature 'Recycle Bin Feature' -Scope ForestOrConfigurationSet -Target $domain -Confirm:$false
        Import-Module ActiveDirectory
        Write-Host "Installed Recycle Bin"
    }
    catch
    {
        Write-Error -Message "Something went wrong!"
    }
}
 
Last edited:
  • Like
Reactions: Brymey