Sekar Chinnakannu
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
- Groups name with users count in entire domain
- Last modified Date
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
- 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
}
$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).
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
}
ASKER
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.
ASKER
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
Group Name, Users Count, Modified Date, OU
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Foreach($G In $GroupArray)
{
Write-Host $G.Name
Write-Host "-------------"
$G.Members
}
Pull all of these into a excel and do a pivot.