Saturday, 8 November 2014

Enable Bulk AD Users From CSV with Powershell

In this article, I am going write powershell script to enable bulk AD user accounts from CSV file. You can use the powershell cmdlet Enable-ADAccount to enable an ad user or computer account.

Enable AD User Account by samAccountName

Import-Module ActiveDirectory
Enable-ADAccount -Identity MorganTest

Enable 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 enable with the column samAccountName.
Enable 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 Enable-Bulk-AD-Users-FromCSV.ps1

Powershell script file: Download Enable-Bulk-AD-Users-FromCSV.ps1
Import-Module ActiveDirectory
Import-Csv "C:\Scripts\Users.csv" | ForEach-Object {
 $samAccountName = $_."samAccountName" 
Get-ADUser -Identity $samAccountName | Enable-ADAccount
Write-Host "-User "$samAccountName" Enabled"
   6. Now run the Enable-Bulk-AD-Users-FromCSV.ps1 file in Powershell console to enable bulk Active Directory users from csv file.


No comments:

Post a Comment