PowerShell: Bulk Enable / Disable Users

KB ID 0001469


I needed to work out how to bulk disable some domain users from a .CSV file this week, so I thought I’d write it up.

Disable Domain Users in Bulk from CSV

Well firstly, you need to have your users in a CSV file. For the live job I just exported all the SamAccountNames to a CSV, but here for testing I just loaded a few in manually;

User Name CSV

Then execute the following two commands;

Import-Module ActiveDirectory 

Import-Csv -Path "C:\Temp\Users-To-Disable.csv" | ForEach-Object {Set-ADUser -Identity $_.’User-Name’ -Enabled $false}

Import-Module ActiveDirectory  Import-Csv -Path "C:\Temp\Users-To-Disable.csv" | ForEach-Object {Set-ADUser -Identity $_.’User-Name’ -Enabled $false}

Let’s have a quick check, and sure enough they are disabled.

Windows Disable users in Bulk

Enable Domain Users in Bulk from CSV

To re-enable them, we just need to change one word in the command, (from false to true).

Import-Module ActiveDirectory 

Import-Csv -Path "C:\Temp\Users-To-Enable.csv" | ForEach-Object {Set-ADUser -Identity $_.’User-Name’ -Enabled $true}

Bulk enable Users from CSV

A quick refresh and our users are enabled again!

Bulk enable windows users

Related Articles, References, Credits, or External Links


Author: PeteLong

Share This Post On


  1. Thanks you, this is what I needed

    Post a Reply
    • Thanks a lot for the script- it worked

      Post a Reply
  2. Thanks a lot for the script, this met my requirement

    Post a Reply

Submit a Comment

Your email address will not be published. Required fields are marked *