Disable Bulk AD Users from CSV file using Powershell Script

Disable Bulk AD Users from CSV file using Powershell Script

  1. Consider the CSV file Users.csv which contains set of Active Directory users to disable with the attribute samAccountName.

2. Copy the below Powershell script and paste in Notepad file.
3. Change the Users.csv file path with your own csv file path.
4. SaveAs the Notepad file with the extension .ps1 like Disable-Bulk-AD-Users-FromCSV.ps1 

Powershell script file: Disable-Bulk-AD-Users-FromCSV.ps1

Import-Module ActiveDirectory

Import-Csv “C:\Scripts\Users.csv” | ForEach-Object {

 $samAccountName = $_.”samAccountName”

Get-ADUser -Identity $samAccountName | Disable-ADAccount

}

  1. Now run the Disable-Bulk-AD-Users-FromCSV.ps1file in Powershell to Disable Bulk Active Directory users from CSV file.

PS C:\Scripts> .\Disable-Bulk-AD-Users-FromCSV.ps1

Note: I have placed script file in the location C:\Scripts, if you placed in any other location, you can navigate to that path using CD path command (like cd “C:\Downloads”).

1 thought on “Disable Bulk AD Users from CSV file using Powershell Script

Leave a Reply

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