We help IT Professionals succeed at work.

How to import users from notepad to a security group.

lianne143
lianne143 asked
on
Hi

I have a notepad called "AllUser" containing 1000 users. I have created a Universal security group in the active directory called "AllMkt" and would like to import all the 1000 users into this universal security group.

Is there any Powershell command  and let me know the best way of doing this.

If it is Powershell please post me the exact syntax that i need to run.

Any tutorials and help much appreciated.
Comment
Watch Question

CERTIFIED EXPERT

Commented:
You could just open powershell and cut and paste the members after you place commas between each user name.
 Add-ADGroupMember -Identity MySecurityGroup -Members Member01,Member02

Open in new window

CERTIFIED EXPERT
Top Expert 2014
Commented:
To save you from typing all those commas:
$members = Get-Content "c:\temp\AllUser.txt"
Add-ADGroupMember -Identity "AllMkt" -Members $members

Open in new window


Your "AllUser.txt" file should contain distinguishedNames, GUIDs, SIDs, or samAccountNames - one per line, no header line, and no blank lines.

Author

Commented:
Hi

Exported only the GUIDs of all the 1000 users to a notepad and ran the above command and it gives an error.

Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.

PS H:\> $members = Get-Content "c:\temp\AllUser.txt"
PS H:\> Add-ADGroupMember -Identity "AllMkt" -Members $members
Add-ADGroupMember : Cannot find an object with identity: '{56F21980-6F13-431+A2:A1188D-A611-99D8E8930101}' under:
'DC=domain,DC=local'.
At line:1 char:1
+ Add-ADGroupMember -Identity "AllMkt" -Members $members
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ({56F21980-6F13-...1-99D8E8930101}:ADPrincipal) [Add-ADGroupMember], ADI
   dentityNotFoundException
    + FullyQualifiedErrorId : SetADGroupMember.ValidateMembersParameter,Microsoft.ActiveDirectory.Management.Commands.
   AddADGroupMember

PS H:\>

I searched the corresponding username of the GUID and the user exist on our AD.

Please let me know if i am missing any thing.

Author

Commented:
Do i need to try with distinguishedNames, SIDs, or samAccountNames ?
CERTIFIED EXPERT
Top Expert 2014

Commented:
When using GUIDs, they shouldn't have the braces at either end.  Also, I see in the GUID for your error sample a "+" and a ":", there should be only letters, numbers, and hyphens ("-").

Author

Commented:
Great footech

That worked  :)

Points awarded and many thanks :)