header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Import groups and export DN
Last Post 31 Jul 2009 07:02 AM by Shay Levy. 9 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
ebrown35User is Offline
New Member
New Member
Posts:30
Avatar

--
22 Jul 2009 07:26 AM

    Import-Csv C:\scripts\delete_groups.csv | Get-QADGroup -Identity {$_.SamAccountName} -SizeLimit 0 -DontUseDefaultIncludedProperties -IncludedProperties dn | Select-Object dn | Export-Csv -Path "C:\scripts\delete_groups_dn.csv"



    The  script above is returning the following error:


    Get-QADGroup : The (&(objectClass=*)(sAMAccountName=TSR))) search filter is invalid.
    At line:1 char:55
    + Import-Csv C:\scripts\delete_groups.csv | Get-QADGroup <<<<   -Identity {$_.SamAccountName} -SizeLimit 0 -DontUseDefa
    ultIncludedProperties -IncludedProperties dn | Select-Object dn | Export-Csv -Path "C:\scripts\delete_groups_dn.csv"
        + CategoryInfo          : NotSpecified: (:) [Get-QADGroup], ArgumentException
        + FullyQualifiedErrorId : System.ArgumentException,Quest.ActiveRoles.ArsPowerShellSnapIn.Cmdlets.GetGroupCmdlet2



    All I am trying to do is import a list of list of groups (sAMAccountName) and return the DN and export the list. What am I missing?

    AythUser is Offline
    Basic Member
    Basic Member
    Posts:232
    Avatar

    --
    22 Jul 2009 07:35 AM
    Try this:

    Import-Csv C:\scripts\delete_groups.csv | Foreach {Get-QADGroup -Identity $_.SamAccountName -SizeLimit 0 -DontUseDefaultIncludedProperties -IncludedProperties dn | Select-Object dn} | Export-Csv -Path "C:\scripts\delete_groups_dn.csv"

    Essentially missing the foreach loop to actually go through the contents of the csv. Cheers.
    My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
    ebrown35User is Offline
    New Member
    New Member
    Posts:30
    Avatar

    --
    22 Jul 2009 07:43 AM
    that returned a similar error:

    Get-QADGroup : The (&(objectClass=*)(sAMAccountName=TSR))) search filter is invalid.
    At line:1 char:64
    + Import-Csv C:\scripts\delete_groups.csv | Foreach {Get-QADGroup <<<<  -Identity $_.SamAccountName -SizeLimit 0 -DontU
    seDefaultIncludedProperties -IncludedProperties dn | Select-Object dn} | Export-Csv -Path "C:\scripts\delete_groups_dn.
    csv"
        + CategoryInfo          : NotSpecified: (:) [Get-QADGroup], ArgumentException
        + FullyQualifiedErrorId : System.ArgumentException,Quest.ActiveRoles.ArsPowerShellSnapIn.Cmdlets.GetGroupCmdlet2
    AythUser is Offline
    Basic Member
    Basic Member
    Posts:232
    Avatar

    --
    22 Jul 2009 07:59 AM
    Interesting it works for me. I created a csv with a couple groups in it. For curiousities sake, what happens if you run

    Get-QADGroup -Identity $_.SamAccountName -SizeLimit 0 -DontUseDefaultIncludedProperties -IncludedProperties dn

    Does it generate output? Also, how was the csv generated?
    My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
    ebrown35User is Offline
    New Member
    New Member
    Posts:30
    Avatar

    --
    22 Jul 2009 08:04 AM
    Get-QADGroup : Cannot validate argument on parameter 'Identity'. The argument cannot be null or empty.
    At line:1 char:23
    + Get-QADGroup -Identity <<<<  $_.SamAccountName -SizeLimit 0 -DontUseDefaultIncludedProperties -IncludedProperties dn
        + CategoryInfo          : InvalidData: (:) [Get-QADGroup], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Cmdlets.GetGroupC
       mdlet2

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

    --
    22 Jul 2009 08:34 AM
    I assume there is a column header in your csv file named 'SamAccountName', the following should work:

    Import-Csv C:\scripts\delete_groups.csv | Get-QADGroup -Identity {$_.SamAccountName} | Select-Object name,dn | Export-Csv "C:\scripts\delete_groups_dn.csv"

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

    --
    30 Jul 2009 11:54 AM
    Yeah Shay there was an incorrect group name in the.csv towards the bottom of the list that was causing it to fail, once I resolved that everything was fine. Now I have to export the members of each one of the groups on the C:\scripts\delete_groups.csv list.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    31 Jul 2009 06:40 AM
    You want to lis the members of each group to a separate csv file or one file for all groups?

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    31 Jul 2009 07:02 AM
    Cool ;-)

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

    --
    31 Jul 2009 07:05 AM
    Shay I found one of your examples in another thread and made on small modification:

    Import-Csv C:\scripts\delete_groups.csv | Get-QADGroup -Identity {$_.Name} | foreach {

    $group = $_

    $group | Get-QADGroupMember | select Name,SAMAccountName,Description,Office,Type,@{n="GroupName";e={$group.name}} | export-csv "c:\scripts\groups\$($group.name).csv" -noType

    }

    It works perfectly!

    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