Solved

Powershell Script to Pull all the AD Group in Domain

Posted on 2014-09-29
7
1,303 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will help you understand what HashTables are and how to use them in PowerShell.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
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 to another domain controller. Log onto the new domain controller with a user account t…

895 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

12 Experts available now in Live!

Get 1:1 Help Now