Skip to main content
IT BIBLESign in

Forum / Off-Topic & Miscellaneous / Scripting & Programming

Enable AD Recycle Bin

WizardTux Cool Guy OP
Jan 12, 2023, 5:47 PM UTC
#1

This was quick and dirty / probably needs some more work I'll add it to GitHub later.

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!"
    }
}

Sign in to reply.