Introduction

In this blog post, I provide a Powershell script which you can use to add users from a text file to an Active Directory group using alternate credentials.

The Powershell script

Start by of users in a text file, in this case, called “users.txt”.

Run the script and enter the credentials that have the appropriate permissions.

Replace “Test_Group” with the group that you want to add the users to.

A tip is to add the -WhatIf statement after “Add-ADGroupMember -Credential $cred -Identity Test_Group -Member $_”, just to make sure that the script does what you want it to do, before putting it in production.

So, like this:

Import-module ActiveDirectory  
$cred = Get-Credential Get-Content ".\users.txt" | % {  Add-ADGroupMember -Credential $cred -Identity Test_Group -Member $_ } 
Add-ADGroupMember -Credential $cred -Identity Test_Group -Member $_ -WhatIf

References

Related posts

4 COMMENTS

  1. Very helpful post! However, if you’re going to post a script for people to follow. I would like to recommend that you do not abbreviate the ForEach-Object with a % symbol. I had to jog my memory banks to remember what alias % was in this example.

    Otherwise, great script example!

  2. Hi,
    What format should the user names be in, within the users.txt? Can I use the Display Name? Only because the list that we are supplied with is the full name (1st-name surname), and not the login name. Thanks.

    Kam.

LEAVE A REPLY

Please enter your comment!
Please enter your name here