header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Adding users to groups from two headers in .csv
Last Post 15 Feb 2010 07:31 AM by Mr Coffee. 7 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
ebrown35User is Offline
New Member
New Member
Posts:30
Avatar

--
02 Dec 2009 12:04 PM
    Ok I have a .csv that contains samaccountname and a group DN for a list of users:

    User                                      Group
    user1                                   ' CN=group1,OU=subcompany,OU=Exchange,DC=Fabrikam,DC=com'
    user2                                   ' CN=group1,OU=subcompany,OU=Exchange,DC=Fabrikam,DC=com'


    How can I write a script that will add the user in the first header to group in the second header. I know that the get-qadgroupmember - add is going to be looking for a user DN.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    02 Dec 2009 11:28 PM
    • Accepted Answer
    import-csv users.csv | foreach { Add-QADGroupMember -Identity $_.group -Member $_.user }

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    ebrown35User is Offline
    New Member
    New Member
    Posts:30
    Avatar

    --
    03 Dec 2009 08:08 AM

    Thanks Shay! Is there a way for it tow work if the group cloumn has more thatn one group in it?

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    03 Dec 2009 12:43 PM
    yes, if there is a character that delimits the groups then you can split on that delimiter, for instance the following is delimited by ";":


    Group
    ' CN=group1,OU=subcompany,OU=Exchange,DC=Fabrikam,DC=com'; ' CN=group2,OU=subcompany,OU=Exchange,DC=Fabrikam,DC=com'



    import-csv users.csv | foreach {
    $user = $_.user
    $_.group.split(";") | foreach { Add-QADGroupMember -Identity $_ -Member $.user }
    }



    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    ebrown35User is Offline
    New Member
    New Member
    Posts:30
    Avatar

    --
    04 Dec 2009 07:03 AM
    Thanks again, I really am starting to get a handle on this.
    Mr CoffeeUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    09 Feb 2010 11:27 AM
    I have a CSV that has group in one colum and users in the second colum where each user is seperated by a ;
    Group1, user1; user2; user3
    Group2, user2; user3; user4


    What would the syntax look like for that import?

    Than you very much.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    09 Feb 2010 11:50 AM
    Assuming the column names are GroupName,Members and you're using Quest AD cmdlets:

    import-csv groups.csv | foreach { Add-QADGroupMember -Identity $_.GroupName -Member $_.Members.Split(";")

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Mr CoffeeUser is Offline
    New Member
    New Member
    Posts:5
    Avatar

    --
    15 Feb 2010 07:31 AM
    How would I go about doing error checking on this script? I find that if it cannot resolve one name it appears to fail to import every one.
    This is a cross org migration and a number of objects did not come over thing were renamed everyone got new SMTP's. If there was a way to dump out to txt the errors but to keep importing it would be a great time saver.

    The process of continuing to attempt to import for a selected group as opposed to importing no one to that list hinders me more than anything.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer