Get Local Admins One-Liner

Working with local users and groups can get a little messy in PowerShell. But I wanted to share a quick one-liner you could use to list all the members of the Administrators group.

This one-liner uses the ADSI type adapter. All you need to do is put in a computer name. My version uses the local computer by referencing $env:computername.

[cc lang=”PowerShell”]
([ADSI]”WinNT://$env:computername/Administrators”).invoke(“Members”) | foreach {$_.getType().InvokeMember(“ADSPath”,”GetProperty”,$null,$_,$null)}
[/cc]

The output will be the ADSI path of all members. This will work remotely as well using your current credentials which, of course, will need admin rights to the remote machine. I cover much more with local users and groups in Managing Active Directory with Windows PowerShell: TFM 2nd Ed from SAPIEN Press which should be out in a few weeks.

One thought on “Get Local Admins One-Liner

Comments are closed.