Tag Archives: Local Administrators

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?