Solved

Powershell Script to Pull all the AD Group in Domain

Posted on 2014-09-29
7
1,352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 25

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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 25

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 25

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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

740 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