Try this. Add user name to Users.csv file. Header should be User Name. Update the group (TestGroup1) with you group name.
Import-module ActiveDirectory Import-CSV "C:\Users.csv" | % { Add-ADGroupMember -Identity TestGroup1 -Member $_.UserName }
http://jrich523.wordpress.com/2011/06/01/methods-for-working-with-active-directory-in-powershell/
that explains your options...
The easiest way (IMHO) is
net group <groupname> <username> /ADD /DOMAIN
But that may not be what you're looking for.
In PowerShell I use the [ADSI] accelerator, which requires only PowerShell V1. I use the Add method to add members to a group, and I check with the IsMember method first to make sure the user is not already a member. For example:
$Group = [ADSI]"LDAP://cn=Test Group,ou=West,dc=MyDomain,dc=com"
$User = [ADSI]"LDAP://cn=Jim Smith,ou=East,dc=MyDomain,dc=com"
If ($Group.IsMember($User.ADsPath) -eq $False)
{
$Group.Add($User.ADsPath)
}
-----
Import-Module ActiveDirectory
Add-ADGroupMember -Identity "Group identifier" -Members "one or more users to add"
Technet reference:
http://technet.microsoft.com/en-us/library/ee617210.aspx
The Identity parameter specifies the Active Directory group that receives the new members. You can identify a group by its distinguished name (DN), GUID, security identifier (SID) or Security Accounts Manager (SAM) account name. You can also specify group object variable, such as $<localGroupObject>, or pass a group object through the pipeline to the Identity parameter. For example, you can use the Get-ADGroup cmdlet to get a group object and then pass the object through the pipeline to the Add-ADGroupMember cmdlet.
The Members parameter specifies the new members to add to a group. You can identify a new member by its distinguished name (DN), GUID, security identifier (SID) or SAM account name. You can also specify user, computer, and group object variables, such as $<localUserObject>. If you are specifying more than one new member, use a comma-separated list. You cannot pass user, computer, or group objects through the pipeline to this cmdlet. To add user, computer, or group objects to a group by using the pipeline, use the Add-ADPrincipalGroupMembership cmdlet.
IMO, this is the best way to do it when you have a bunch of users to add. Make sure the header is UserName and not User Name (no space)
(Yes, I realize this is an old post but it helped me today!)
I get the error Cannot validate arguments on parameter 'Members' The argument is null or empty. Is the TestGroup1 supposed to be just the name of the AD group without quotes or is it a fully qualified LDAP to the group?
- Edited by Tashfin Thursday, May 22, 2014 1:57 PM
I have no idea which script you're referring to, as there are many options mentioned in this thread.
You'll get better help by starting your own thread. Make sure you post your code and your errors, but don't post a screenshot. Use the 'Insert Code Block' feature.
(Get-ADForest).GlobalCatalogs
)If ($Group.IsMember($User.ADsPath) -eq $False)
how use it with ActiveDirectory module and powershell 3.0 and 4.0 ?
If ($Group.IsMember($User.ADsPath) -eq $False)
how use it with ActiveDirectory module and powershell 3.0 and