Add Users to a Group–PowerShell Script

Add Users to a Group using a PowerShell Script C2

3.4 Star
39,997 times
Add to favorites
Active Directory
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Very basic question...
    1 Posts | Last post February 13, 2017
    • Hi Santhosh 
      In the text file (and on your page here: there are line breaks:
      Import-module ActiveDirectory 
      Import-CSV "C:\Scripts\Users.csv" | % { 
      Add-ADGroupMember -Identity TestGroup1 -Member $_.UserName 
      Why is the text broken up...?  I get the same result whether I paste in in one block, or line breaks.
      I often see PowerShell examples online that are broken up, but I've never known why.  (Like I say... a very basic question!)
      Thanks,  Richard
  • Excellent script
    1 Posts | Last post June 10, 2016
    • Really helpful, thank you Santhosh
  • Unix Attributes Fail To Update
    1 Posts | Last post February 11, 2016
    • Hi Santhost,
      There is an error on that script. The Unix UID attribute is configured to raise on each iteration, meaning that each new user inside a csv will be assigned a different UID, the value of msSFU30MaxUidNumber is nowhere updated.
      In that way if you run multiple times the scripts users maybe assigned with the same UID number.
      The following should be included
      Set-ADObject $NIS -Replace @{msSFU30MaxUidNumber = $maxUid}
      after setting each user's ID.
  • How would you mass import to another multi valued field
    1 Posts | Last post October 21, 2015
    • How can you import a list of items in to a different multi valued field, like ProxyAddress in a AD Group.
  • Multiple Imports in One Script
    1 Posts | Last post November 12, 2014
    • Hi,
      Thank you for the script. 
      I'm new to PowerShell. Can multiple CSV files be imported in one script or do I need a new script for each CSV file?
  • How add multiple values for memberof attribute
    1 Posts | Last post May 16, 2013
    • Many users join's at company every day,we have a csv format file with the new user's to be add to Active Directory, but a single user can be member of 1,2,3,etc groups, the cuestion is ¿How can I tell A.D. tht the first row must be an insert for the new employee and the other rows for the same employee are just a new group to be added to this user? I can't figure out how to do it =/... any suggestion will be appreciated :)
      By the way.. sorry about my english.. I do my best
  • Wondering if I could get help with a modification of your script.
    2 Posts | Last post May 14, 2013
    • # Add User to a Group - PowerShell Script 
      Import-module ActiveDirectory  
      $ExportGroupName = Read-Host "Enter Group Name for Export."
      $FileNameExport = Read-Host "Enter the path you wish to Export the CSV to."
      %{Get-ADGroupMember -Identity $ExportGroupName | Select sAMAccountName} | Export-Csv $FileNameExport
      $FileNameImport = Read-Host "Enter path to CSV file that you wish to import."
      $GroupName = Read-Host "Enter Group Name for Import"
      Import-CSV $filename | % {  
      Add-ADGroupMember -Identity $GroupName -Member $_.sAMAccountName
      Thing is the export adds a line row in A1 of the spreadsheet.
      #TYPE Selected.Microsoft.ActiveDirectory.Management.ADPrincipal
      Is there a way to tell the $_. to skip the first row?
    • Export-CSV -NoTypeInformation will NOT Export the first Line to CSV
  • thanks for this script, what about 2008 not R2
    1 Posts | Last post May 08, 2013
    • if i want to run this script on windows server 2008 not R2 what is your recommendations 
  • Does it write a log?
    1 Posts | Last post April 25, 2012
    • Will using this Powershell script write a log if there are any failures? If so, can it be specified where to write it?
  • Wanted to Add Computer accounts to a security Groups
    5 Posts | Last post December 06, 2011
    • Wanted to computer accounts to a security group? Can I use the same script to achieve that ? Or do you've some other script readily available?
    • hey Anoop,
      why dont you use DSQuery DSADD to add computers to AD sec group as simple as such .
      Create a batch file with DSADD commond and run it with list of computers.
    • Atlast I got the one which I was looking for :)
    • Sorry guys.  Somehow I missed this conversation.  I am glad that you got a solution.  Please let me know if you have any more questions.  Thanks, 
    • An00p,
      You can use the same logic to add computers to a group.  Make sure the input file contains the computer name ends with $ (TestComper1$)
1 - 10 of 13 Items