PeetersOnline.nl
Helpful Function of the Day: Get-LocalAdmins
The following function uses the ADSI provider and some tricks to determine the members of the local Administrators group on any of your Windows Servers. Check it out:
function Get-LocalAdmins
{
param([string]$serverName)
$ErrorActionPreference = “Stop”
If ($serverName -eq “”)
{
Write-Host “Usage: Get-LocalAdmins“`
-ForegroundColor yellow
}
Else
{
$Group = [ADSI]“WinNT://$serverName/Administrators”
$Memberlist = @($Group.PSBase.Invoke(“Members”))
$Members = $Memberlist |
%{$_.GetType().InvokeMember(“Name”,’GetProperty’,$null,$_,$null)}
Return $Members
}
}
You use it simply by typing Get-LocalAdmins MYSERVER. Ain’t that neat?
No related posts.
4 Responses to Helpful Function of the Day: Get-LocalAdmins
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





Hi,
I am new to the scripting.Could you please let me know how to run this function?
Thanks,
Sumit
1. Save it as Get-LocalAdmins.ps1
2. Start Powershell
3. Dot-source the script by typing the full path to the script, preceeded by a dot and a space
4. Run Get-LocalAdmins YOURSERVERNAME
Hugo
Thanks…it works…
UPDATE: Be advised that this command might generate warning events in the System Event Log with Event-ID 2510: The server service was unable to map error code 1722. Other sources on the internet will tell you this error code means The RPC Server was unavailable. I believe this error message is benign. If anybody can give more insight on this, please add a comment.
Hugo