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.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

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.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

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.

reports

Powered by Buttondown.

Join me on Mastodon

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

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