Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Get Local Admins One-Liner

Posted on March 14, 2011

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.

Share this:

  • Print (Opens in new window) Print

Like this:

Like Loading…

Related

1 thought on “Get Local Admins One-Liner”

  1. Hugo says:
    March 16, 2011 at 8:41 am

    Here’s my take on it using a little function:
    http://www.peetersonline.nl/index.php/powershell/helpful-function-of-the-day-get-localadmins/

Comments are closed.

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2026 The Lonely Administrator | Powered by SuperbThemes!
%d