Powershell – Get members of AD Group

Sometimes you will need a fast and easy way to list who is a member of a AD group.  Start Powershell and enter either of the following commands:

Get-ADGroupMember -Identity "TestGroup" | Select samAccountName,Name,@{Name="DisplayName";Expression={(Get-ADUser $_.distinguishedName -Properties displayname).Displayname}},@{Name="Title";Expression={(Get-ADUser $_.distinguishedName -Properties Title).title}}
Get-ADGroupMember -Identity "TestGroup" | Select samAccountName,Name
Get-ADGroupMember -Identity "TestGroup" | Select samAccountName

Sometimes you will want the output to a textfile, add > textfile.txt

Get-ADGroupMember -Identity "TestGroup" | Select samAccountName,Name  > textfile.txt


Sometime you will want a list of all users with last password set in entire branch of AD:

$path = "OU=Greenland,DC=group,DC=Denmark,DC=dk"

$users = Get-ADUser -Filter * -Properties PasswordLastSet | Sort PasswordLastSet -Descending | Select Surname,GivenName,SamAccountName,Enabled,PasswordLastSet