Showing posts with label Active Directory. Show all posts
Showing posts with label Active Directory. Show all posts

Friday, November 16, 2012

Get Active Directory Group Members with PowerShell

I’ve not blogged for quite a while. Let’s come back with a small PowerShell script for retrieving Active Directory Group Members.

The bellow scripts retrieve all the Active Directory groups in a specific OU and count the number of members.

Import-Module ActiveDirectory

$groups = Get-ADGroup -searchbase "OU=MyOU,DC=myDC,DC=net" -filter *

$myArray = @()

foreach($g in $groups)

{

$members = Get-ADGroupMember($g)

$myObject = New-Object System.Object

$myObject | Add-Member -type NoteProperty -name Name -Value $g.Name

$myObject | Add-Member -type NoteProperty -name Count -Value $members.Length

$myArray += $myObject

}

$myArray