Solved

Powershell Script to Pull all the AD Group in Domain

Posted on 2014-09-29
7
1,283 Views
Last Modified: 2014-09-30
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
0
Comment
Question by:Sekar Chinnakannu
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:ambatihp
ID: 40351529
$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.
0
 
LVL 24

Author Comment

by:Sekar Chinnakannu
ID: 40351544
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
0
 
LVL 5

Expert Comment

by:Abdul Khadja Alaoudine
ID: 40351648
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
 }
0
 
LVL 24

Author Comment

by:Sekar Chinnakannu
ID: 40351711
Also can you please help me to get output in CSV file
0
 
LVL 5

Expert Comment

by:Abdul Khadja Alaoudine
ID: 40351712
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.
0
 
LVL 24

Author Comment

by:Sekar Chinnakannu
ID: 40351714
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
0
 
LVL 5

Accepted Solution

by:
Abdul Khadja Alaoudine earned 500 total points
ID: 40351825
Here we go...

$GroupArray = Get-ADGroup -Properties Modified, Members -Filter * -SearchBase "DC=yourcompany,DC=local"
$GroupArray | Select Name,@{Name="Users Count";Expression={($_.members).count}},Modified,DistinguishedName | Export-CSV "Groups.csv"
0

Join & Write a Comment

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now