Getting Local Group Members

by Dec 20, 2013

In PowerShell, local accounts and groups can be managed in an object-oriented way thanks to .NET Framework 3.51 and above. This will list local administrator accounts:

Add-Type -AssemblyName System.DirectoryServices.AccountManagement

$type = New-Object DirectoryServices.AccountManagement.PrincipalContext('Machine', $env:COMPUTERNAME)

$group = [DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($type, 'SAMAccountName', 'Administrators')

$group.Members | Select-Object -Property SAMAccountName, LastPasswordSet, LastLogon, Enabled 

You can get a lot more, though. Try and query the group by itself:

 

Or try and view all properties for all members:


Twitter This Tip! ReTweet this Tip!