Issue with Get-ADGroup and -recursive

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of blahblah8686 blahblah8686 2 years ago.

  • Author
    Posts
  • #27300
    Profile photo of blahblah8686
    blahblah8686
    Participant

    Hey all,

    I am running into an issue when running a script to all get all the members for each group in AD. The script works fine without -recursive but as soon as I add it I get this error:

    Get-ADGroup : A parameter cannot be found that matches parameter name 'recursive'.
    At line:3 char:47
    + $Groups = Get-ADGroup -Properties * -Filter * -recursive -SearchBase "OU=Securit ...
    + ~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Get-ADGroup], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADGrou

    Import-Module ActiveDirectory

    $Groups = Get-ADGroup -Properties * -Filter * -recursive -SearchBase "OU=Security Groups,DC=local,DC=company,DC=org"

    $Table = @()

    $Record = [ordered]@{
    "Group Name" = ""
    "Name" = ""
    "Username" = ""
    }

    Foreach ($Group in $Groups)
    {

    $Arrayofmembers = Get-ADGroupMember -identity $Group | select name,samaccountname

    foreach ($Member in $Arrayofmembers)
    {
    $Record."Group Name" = $Group
    $Record."Name" = $Member.name
    $Record."UserName" = $Member.samaccountname
    $objRecord = New-Object PSObject -property $Record
    $Table += $objrecord

    }

    }

    $Table | # export-csv "C:\temp\SecurityGroups.csv" -NoTypeInformation
    Out-GridView

    Any ideas would be very helpful. Thanks!

  • #27301
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    It's Get-ADGroupMember which has the -Recursive parameter, not Get-ADGroup.

  • #27313
    Profile photo of blahblah8686
    blahblah8686
    Participant

    Thanks for the help Dave.

    I was able to get it working without changing Get-ADGroupMember.

    `Import-Module ActiveDirectory

    $Groups = Get-ADGroup -Properties * -Filter * -SearchBase "OU=Security Groups,DC=local,DC=company,DC=org"

    $Table = @()

    $Record = [ordered]@{
    "Group Name" = ""
    "Name" = ""
    "Username" = ""
    }

    Foreach ($Group in $Groups)
    {

    $Arrayofmembers = Get-ADGroupMember -recursive -identity $Group | select name,samaccountname

    foreach ($Member in $Arrayofmembers)
    {
    $Record."Group Name" = $Group
    $Record."Name" = $Member.name
    $Record."UserName" = $Member.samaccountname
    $objRecord = New-Object PSObject -property $Record
    $Table += $objrecord

    }

    }

    $Table | # export-csv "C:\temp\SecurityGroups.csv" -NoTypeInformation
    Out-GridView`

You must be logged in to reply to this topic.