Link to home
Start Free TrialLog in
Avatar of Sekar Chinnakannu
Sekar ChinnakannuFlag for Singapore

asked on

Powershell Script to Pull all the AD Group in Domain

Team, Need help on getting Powershell Script to Pull all the AD Group in Domain. I need the below output in report.

- Groups name with users count in entire domain
- Last modified Date
Avatar of ambatihp
ambatihp

$GroupArray = Get-ADGroup -Properties * -Filter * -SearchBase "DC=corp,DC=yourcompany,DC=local"
Foreach($G In $GroupArray)
{
    Write-Host $G.Name
    Write-Host "-------------"
    $G.Members
}

Pull all of these into a excel and do a pivot.
Avatar of Sekar Chinnakannu

ASKER

I am getting all users, computers as output, I am looking for a script to generate all groups in a domain.

- AD Group name with users count in entire domain
- Last modified Date
Below script will give you list of AD groups with memeber count in each group and modifed date for the groups.

$GroupArray = Get-ADGroup -Properties Modified, Members -Filter * -SearchBase "DC=yourcompany,DC=local"
Foreach($Group In $GroupArray)
 {
     Write-Host
     Write-Host "Group Name:"$Group.Name
     Write-Host "Total members:"($Group.Members).count
     Write-Host "Modified date:"$Group.modified
     Write-Host
 }

To get total number of users in domain

$users = Get-ADUser -Filter * -SearchBase "DC=yourcompany,DC=local"
$users.count

To get list of users and their modified date

$UserArray = Get-ADUser -Filter * -SearchBase "DC=yourcompany,DC=local" -Properties Modified
Foreach($User In $UserArray)
 {
     Write-Host
     Write-Host "User Name:"$User.Name
     Write-Host "Modified date:"$User.modified
     Write-Host
 }
Also can you please help me to get output in CSV file
Looks like you added 'To get total number of users in domain' line to the script. Remove it, save the ps1 file and try again.
Its working fine, can you help me to add OU details for the group and same need to generate as csv file like below format.

Group Name, Users Count, Modified Date, OU
ASKER CERTIFIED SOLUTION
Avatar of Abdul Khadja Alaoudine
Abdul Khadja Alaoudine

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial