KB ID 0001469
Problem
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;
Then execute the following two commands;
[box]
Import-Module ActiveDirectory
Import-Csv -Path "C:\Temp\Users-To-Disable.csv" | ForEach-Object {Set-ADUser -Identity $_.’User-Name’ -Enabled $false}
[/box]
Let’s have a quick check, and sure enough they are disabled.
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).
[box]
Import-Module ActiveDirectory
Import-Csv -Path "C:\Temp\Users-To-Enable.csv" | ForEach-Object {Set-ADUser -Identity $_.’User-Name’ -Enabled $true}
[/box]
A quick refresh and our users are enabled again!
Related Articles, References, Credits, or External Links
NA
Thanks you, this is what I needed
Thanks a lot for the script- it worked
Thanks a lot for the script, this met my requirement
Will your script search through OU’s recursively if the AD accounts are nested Pete.
Thanks
Wasim
I’d have to test it but I think it probably will?
simple and easy to understand.
Other sites have many scripts and they work but this one does the job in one line!