MilesLogan
asked on
Add AD Users to different groups from a csv file with powershell
ASKER
Hi Will ..
I changed he headed to "group" and I tested it with User and SamAccountname and I receive the error below.
Add-ADGroupMember : A parameter cannot be found that matches parameter name 'User'.
At C:\PS\AddGroupstoUsers.ps1 :5 char:42
+ Add-ADGroupMember -Identity $User.Group -User $User.SamAccountname -Confirm:$fa ...
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-ADGroupMember], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Mic rosoft.Act iveDirecto ry.Managem ent.Comman ds.AddADGr oupMember
Add-ADGroupMember : A parameter cannot be found that matches parameter name 'User'.
At C:\PS\AddGroupstoUsers.ps1 :5 char:42
+ Add-ADGroupMember -Identity $User.Group -User $User.SamAccountname -Confirm:$fa ...
+ ~~~~~
I changed he headed to "group" and I tested it with User and SamAccountname and I receive the error below.
Add-ADGroupMember : A parameter cannot be found that matches parameter name 'User'.
At C:\PS\AddGroupstoUsers.ps1
+ Add-ADGroupMember -Identity $User.Group -User $User.SamAccountname -Confirm:$fa ...
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Add-ADGroupMember], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Mic
Add-ADGroupMember : A parameter cannot be found that matches parameter name 'User'.
At C:\PS\AddGroupstoUsers.ps1
+ Add-ADGroupMember -Identity $User.Group -User $User.SamAccountname -Confirm:$fa ...
+ ~~~~~
I think you need to change the heading of the group column to "DN" for distinguished name and then add the DN of each group where you have group names.
To find the DN of each group you can go to the attributes tab of the group from active directory users and computers. You will need to have "advanced features" ticked to see the tab.
To find the DN of each group you can go to the attributes tab of the group from active directory users and computers. You will need to have "advanced features" ticked to see the tab.
Miles,
In your .csv file change the samaccountname heading to UserName, your other heading is acceptable for the group. I have attached the powershell script you want to run. Make sure you change the extension from .txt to .ps1 as Experts Exchange doesn't accept .ps1 attachements. Wherever you have saved the .ps1 file I want you to cd to that location and then in powershell
your syntax will be .\Addtogroups.ps1 **then press enter and let it go!! :) **
**right-click powershell and run as administrator**
Addtogroups.txt
In your .csv file change the samaccountname heading to UserName, your other heading is acceptable for the group. I have attached the powershell script you want to run. Make sure you change the extension from .txt to .ps1 as Experts Exchange doesn't accept .ps1 attachements. Wherever you have saved the .ps1 file I want you to cd to that location and then in powershell
your syntax will be .\Addtogroups.ps1 **then press enter and let it go!! :) **
**right-click powershell and run as administrator**
Addtogroups.txt
ASKER
Hi FoxLuv .. I receive a similar error with yours ..
PS C:\PS> C:\PS\Add2GroupsTEst.ps1
Add-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null
argument and try the command again.
At C:\PS\Add2GroupsTEst.ps1:3 char:29
+ Add-ADgroupmember -Identity $_.group_name -Member $_.UserName
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-ADGroupMember], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nError,Mic rosoft.Act iveDirecto ry.Managem ent.Comman ds.AddADGr
oupMember
Add-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null
PS C:\PS> C:\PS\Add2GroupsTEst.ps1
Add-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null
argument and try the command again.
At C:\PS\Add2GroupsTEst.ps1:3
+ Add-ADgroupmember -Identity $_.group_name -Member $_.UserName
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-ADGroupMember], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
oupMember
Add-ADGroupMember : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null
At the top of your .csv file, for the groups is it still reading group_name or did you change it?
ASKER
I changed it Group .. i tested both options below.
SamAccountName,Group and UserName,Group
SamAccountName,Group and UserName,Group
Tell me what the top of your .csv file reads now or send me a screen shot of your .csv . My script has to match your headings or it will not work.
ASKER
Column A = SamAccountName
Column B = Group
Column B = Group
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did it .. thanks !
Your welcome buddy!!
Change the Heading for Group_Name to Group.
Open in new window
Thats it.
Will.