Add Users to a Group–PowerShell Script

Add Users to a Group using a PowerShell Script C2

 
 
 
 
 
(34)
16,945 times
Add to favorites
Active Directory
12/6/2011
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • 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. http://technet.microsoft.com/en-us/library/cc754037(WS.10).aspx
    • Atlast I got the one which I was looking for :)
      
      See, http://gallery.technet.microsoft.com/Add-Computers-To-A-abc99ab6
    • 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$)
  • Format?
    2 Posts | Last post November 23, 2011
    • What is the format of the Users.csv file?
      
      Thanks
    • It is the samaccountname with UserName as the header.  You can see the sample file in my following blog:
      
      
      http://portal.sivarajan.com/2011/07/add-users-to-grouppowershell-script.html
      
  • Error: Import-Module
    3 Posts | Last post November 09, 2011
    • Attempted to run this script, but get an error.
      
      "Import-Module : The specified module 'ActiveDirectory' was not loaded because no valid module file was found in any module directory..."
      
      Should the "ActiveDirectory" be changed to my AD domain name?
      
      Any other parameter changes that should be made based on my local names/settings?
      
      Thanks in advance!
      
    • No. It is an Active Directory PowerShell module - http://technet.microsoft.com/en-us/library/dd378937(WS.10).aspx
      
      Add-ADGroupMember cmdlet is part of this module.  
      
      What version of OS are you using?
      
      
      
    • Any update on this?  Were you able to resolve the issue? 
  • Adding Local users (with Remote desktop Rights) to W2K8R2 using Powershell
    3 Posts | Last post November 09, 2011
    • Hi Santhosh,
      Searhcing around I found your info and wanted to ask how to use a csv file to import users names, password, group as administrator, and add to remote desktop users.
      I have 30 Windows 2008 R2 Servers set up on a workgroup with no Active Directory.  Main purpose for adding these users are so they can remote desktop to the box with their own account.
      Thanks much.
      Ex:
      User | Login | Password | Group
      first| first  | pw | administrator
      
      Thanks in advance for any information you can give me,
      Rob
    • You can’t really add user accounts like that. If you don’t have AD, you need to create a local user account on the Windows 2008 R2 server itself and then add them to the remote desktop users group (or RDP permission) on the server.   Users have to use Server\UserAccount to login.  
    • Any update on this?  Please let me know if you have more questions.