Author Posts

July 8, 2015 at 6:26 am

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!

July 8, 2015 at 6:30 am

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

July 8, 2015 at 10:02 am

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`