Saturday, 8 November 2014

Disable Bulk AD Users from CSV using Powershell

In Powershel, you can disable an AD user account by using the Active Directory Powershell cmdlet Disable-ADAccount.

Disable AD User Account by its samAccountName

Import-Module ActiveDirectory
Disable-ADAccount -Identity MorganTest

Disable Bulk AD Users from CSV file using Powershell Script

   1. Consider the CSV file Users.csv (Ex file: Download ADUsers.csv) which contains set of Active Directory users to disable with the column header samAccountName.
Disable Bulk AD Users From CSV - Powershell
   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: Download 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
   6. Now run the Disable-Bulk-AD-Users-FromCSV.ps1 file from Powershell console to disable bulk Active Directory users from csv file.


No comments:

Post a Comment