Query OU – Get Groups – Get Group Members – Export to CSV
The AI result did not work I am getting an error. The error is “Get-ADGroupMember: The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.”
Import-Module ActiveDirectory
# Specify the OU where your groups are located
$SearchBase = “CN=test,DC=test,DC=LOC”
# Get all groups within the specified OU
$Groups = Get-ADGroup -Filter * -Properties * -SearchBase $SearchBase
# Initialize an empty array to store group members
$GroupMembers = @()
foreach ($Group in $Groups) {
$Members = $Group | Get-ADGroupMember
foreach ($Member in $Members) {
$Info = New-Object psObject
$Info | Add-Member -MemberType NoteProperty -Name “GroupName” -Value $Group.Name
$Info | Add-Member -MemberType NoteProperty -Name “Description” -Value $Group.Description
$Info | Add-Member -MemberType NoteProperty -Name “Member” -Value $Member.Name
$GroupMembers += $Info
}
}
# Export the results to a CSV file
$GroupMembers | Sort-Object GroupName | Export-CSV C:tempgroup_members.csv -NoTypeInformation
The AI result did not work I am getting an error. The error is “Get-ADGroupMember: The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.” Import-Module ActiveDirectory# Specify the OU where your groups are located$SearchBase = “CN=test,DC=test,DC=LOC”# Get all groups within the specified OU$Groups = Get-ADGroup -Filter * -Properties * -SearchBase $SearchBase# Initialize an empty array to store group members$GroupMembers = @()foreach ($Group in $Groups) {$Members = $Group | Get-ADGroupMemberforeach ($Member in $Members) {$Info = New-Object psObject$Info | Add-Member -MemberType NoteProperty -Name “GroupName” -Value $Group.Name$Info | Add-Member -MemberType NoteProperty -Name “Description” -Value $Group.Description$Info | Add-Member -MemberType NoteProperty -Name “Member” -Value $Member.Name$GroupMembers += $Info}}# Export the results to a CSV file$GroupMembers | Sort-Object GroupName | Export-CSV C:tempgroup_members.csv -NoTypeInformation Read More