Thursday, May 23, 2013

Add multiple users to an AD Group via PowerShell Script


Below are the commands that can be run as a PowerShell Script to add a list of users to AD.


Import-module ActiveDirectory
$Group1 = Read-Host "Enter the Group Name to which users have to be added :"
  
Add-ADGroupMember -Identity $Group1 -Member (Get-Content c:\Temp\Users.txt) 

Guidelines:


Ø  Login to the server with AD role.
Ø  Create a text file C:\Temp\Users.txt and store the user names you want to add or remove in AD.
Ø  Once you execute the script, it’ll prompt you to enter the Group Name.
Ø  Enter the Group Name and enter.

This Script can be used for bulk addition and bulk removal of user accounts in AD.

Note: Store the domain names in Users.txt file. 

2 comments: