Help using Get-ADgroup RRS feed

  • General discussion

  • Hello.....How can I get this to except my "GroupName" in the second example?

    Example 1. This Works

    $Results = Get-ADgroup -LDAPFilter "(name=My_Group_Name)" | Select-Object -ExpandProperty "Name"

    Example 2. This doesn't

    $GroupName = "My_Group_Name" 
    $Results = Get-ADgroup -LDAPFilter "(name=$GroupName)" | Select-Object -ExpandProperty "Name"

    Example 3. works but too slow

    $Results = get-adgroup -Filter 'GroupCategory -eq "Security" -and GroupScope -eq "Global"' '
    | Where-Object {$_.Name -eq "My_Group_Name"} 
    | Get-ADGroupMember | select name -ExpandProperty "Name"

    The quickest search method in my environment is to use the -LDAPFilter  instead of  -Filter

    Thank you

    Thursday, June 26, 2014 9:27 AM

All replies

  • Hi Hecktor,

    Example two works just fine for me. Does it throw any errors or is it just a null return?

    Example three is of course extremely slow. First you retrieve all global security groups and only after you have them all do you start filtering out those you do not want. You really want to put the name property into the filter ...


    There's no place like

    Thursday, June 26, 2014 9:37 AM
  • Thanks Fred,

    Must have been a issue on my machine as it's ok after a reboot :)

    Thursday, June 26, 2014 9:50 AM