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

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
  • I use this script with a corresponding csv file to handle my user imports, groups and FSRM quotas for students at schools. The CSV has the following headers - "Username,GivenName,MiddleInitial,Surname,DisplayName,UserPrincipalName,Description,Password,Path,RootFolder,RootShare,




    #Check for FSRM Feature
        if ( -not (Get-WindowsFeature | where {$ -eq "FS-Resource-Manager"})){
            Install-WindowsFeature -Name "FS-Resource-Manager"
            } else {
                Write-Host "FS-Resource-Manager is installed"
            #Import the CSV and loop through each row
            Import-Csv "$PWD\Staff.csv" | ForEach-Object {
                #Create the User
                New-ADUser -Name $_.DisplayName -UserPrincipalName $_.UserPrincipalName -SamAccountName $_.Username -GivenName $_.GivenName -DisplayName $_.DisplayName -Initials $_.MiddleInitial -SurName $_.Surname -Description $_.Description -Path $_.Path -AccountPassword (ConvertTo-SecureString $_.Password -AsPlainText -force) -Enabled $True -PasswordNeverExpires $True -PassThru
                #Add the user to Groups if they exist
                if ($_.PrimaryMembership1 -ne "") { Add-ADGroupMember -Identity $_.PrimaryMembership1 -Member $_.Username}
                if ($_.PrimaryMembership2 -ne "") { Add-ADGroupMember -Identity $_.PrimaryMembership2 -Member $_.Username}
                if ($_.PrimaryMembership3 -ne "") { Add-ADGroupMember -Identity $_.PrimaryMembership3 -Member $_.Username}
                if ($_.PrimaryMembership4 -ne "") { Add-ADGroupMember -Identity $_.PrimaryMembership4 -Member $_.Username}
                if ($_.PrimaryMembership5 -ne "") { Add-ADGroupMember -Identity $_.PrimaryMembership5 -Member $_.Username}
                #Create the Home Directories
                $Home_Path = $_.RootFolder + "\" + $_.Username
                $Home_Path_MyDocs = $_.RootFolder + "\" + $_.Username + "\My Documents"
                if ( -not (Test-Path $Home_Path)){New-Item -Path $Home_Path -ItemType Directory}
                if ( -not (Test-Path $Home_Path_MyDocs)){New-Item -Path $Home_Path_MyDocs -ItemType Directory}
                #Set Permisions on the Home Directories
                $acl = Get-Acl -path $Home_Path
                $NewACL= $_.Username,"FullControl","ContainerInherit,ObjectInherit","None","Allow"
                $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $NewACL
                $acl | Set-Acl $Home_Path
                #Share the Home Folder
                $ShareName = $_.Username + "$"
                New-SmbShare Name "$ShareName" Path "$Home_Path" -FullAccess "Everyone"
                #Set the Home Folder and Drive Letter in AD
                $Home_Share_MyDocs = $_.RootShare + "\" + $ShareName + "\My Documents"
                Get-ADUser -Identity $_.Username | set-ADUser -HomeDirectory $Home_Share_MyDocs -HomeDrive $_.HomeDriveLetter   
                #Set FSRM Quota if reuested
                if ($_.EnableFSRMQuota -eq "Y") {New-FsrmQuota -Path $Home_Path -Description "1GB Limit" -Size 1GB}
  • I am having a different issue, PowerShell issue,

Reply Children
No Data