0
votes

I have a script that gets group name and member information, but I want it to also retrieve domain,groupname,type, description,distingushedname, managedby, members, fullname, username and display name. I have added a get-user command (the last line) but dont know how to incorporate it to the working part of the script.

Get-ADGroup -Filter {GroupCategory -eq "Security" -and Name -like "*"}| %{ $Group = $_.Name Get-ADGroupMember $Group | Select @{N="GroupName";E={$Group}},@{N="Member";E={$_.Name}}" }| Export-Csv C:\Users\Desktop\AD\Report.csv -nti Get-ADUser -Filter * -properties * | select fullname*, username*, disp*,distinguishedName*,GroupName,GroupCategory,Member

1

1 Answers

0
votes

It looks like all you need is:

  • store entire group object in $Group
  • pipe result of Get-ADGroupMember to Get-ADUser
  • use $Group in Select-Object to add group properties to user properties.

Sample code:

Get-ADGroup -Filter * -Properties * | ForEach-Object {
    $Group = $_
    Get-ADGroupMember $Group | 
        Where-Object { $_.objectClass -eq 'user'} | 
        Get-ADUser -Properties * | Select-Object FullName, SamAccountName, Disp*, DistinguishedName, @{
            Name = 'GroupName'
            Expression = { $Group.Name }
        }, @{
            Name = 'GroupCategory'
            Expression = { $Group.GroupCategory }
        }, @{
            Name = 'ManagedBy'
            Expression = { $Group.ManagedBy }
        }

}