Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Adding Members to an AD Group via a CSV file ...

$
0
0

I am an absolute beginner on this one.

Can any of you help me with a simple task of adding around 1000 names saved in a CSV file to an AD Group via a power shell script ?

It all looked simple but it is not... .

--------------------------

I tried the below: What am I doing wrong ? ( any help is appreciated. )

I am trying this below script that I have created based on the advice given by others on internet and this forum:

Import-module ActiveDirectory  

$members = Import-CSV "C:\Group_Users.csv" 

$members | ForEach-Object {Add-ADGroupMember -Identity GroupName -Members $_.UsamAccountName  

}

----------------another version ---------------

Import-module ActiveDirectory  

Import-CSV "C:\Scripts\Users.csv" | % {  

Add-ADGroupMember -Identity GroupName -Member $_.UserName  

 

------------------and I get this error ----------------------

Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argument is null or empty. Provide an argument that i

At N:\DVP\PSScripts\AddUserstoGroup.ps1:30 char:78

+ $members | ForEach-Object {Add-ADGroupMember -Identity FmrReporting -Members $_. ...

+                                                                              ~~~

    + CategoryInfo          : InvalidData: (:) [Add-ADGroupMember], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember


Viewing all articles
Browse latest Browse all 6937

Trending Articles