← script library

Enable an Active Directory User with PowerShell

Active DirectoryAugust 17, 2026

The counterpart to the disable script: re-enables one account by sAMAccountName, skips the work when it is already enabled and verifies the result. Both are deliberately single-purpose so they can be wired to a self-service action without a review of what else the script might touch.

powershell
# Enable an AD User Account
# Single use case: re-enable one previously disabled user account
#-----------------------------------------------------------------

function Write-Log {
    param($Message)
    Write-Host "<WRITE-LOG = `"*$Message*`">"
}

# --- Parameters (replace via ServerEngine API parameters if needed) ---
$SamAccountName = "j.doe"

if (-not (Get-Module -ListAvailable -Name ActiveDirectory)) {
    Write-Log "ActiveDirectory module not available on this host!"
    return
}
Import-Module ActiveDirectory

$user = Get-ADUser -Filter "SamAccountName -eq '$SamAccountName'" -Properties Enabled -ErrorAction SilentlyContinue
if ($null -eq $user) {
    Write-Log "User not found: $SamAccountName"
    return
}

if ($user.Enabled) {
    Write-Log "User $SamAccountName is already enabled."
    return
}

Enable-ADAccount -Identity $user.DistinguishedName
$user = Get-ADUser -Identity $user.DistinguishedName -Properties Enabled

if ($user.Enabled) {
    Write-Log "User $SamAccountName enabled successfully."
} else {
    Write-Log "WARNING: User $SamAccountName is still disabled!"
}

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.