← script library

Bulk Disable Active Directory User Accounts

Active DirectoryJanuary 6, 2025

Managing user accounts effectively is essential for maintaining security in your organization. This PowerShell script allows administrators to bulk disable user accounts in Active Directory based on a list in a CSV file. By automating the account disabling process, IT departments can ensure that inactive or terminated accounts are promptly managed. At ServerEngine, we provide powerful tools to streamline your IT management tasks.

powershell
Import-Module ActiveDirectory

function Disable-ADUserAccounts {
    param (
        [string]$csvPath
    )
    $users = Import-Csv -Path $csvPath
    foreach ($user in $users) {
        $username = $user.UserName
        try {
            Disable-ADAccount -Identity $username
            Write-Host "Successfully disabled user: $username"
        } catch {
            Write-Host "ERROR: Could not disable user: $username. Error: $_"
        }
    }
}

Disable-ADUserAccounts -csvPath "C:\Path\To\Your\disable_users.csv"

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.