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
 $ErrorActionPreference = “Stop”
 If ($serverName -eq “”)
  Write-Host “Usage: Get-LocalAdmins “`
  -ForegroundColor yellow
 $Group = [ADSI]”WinNT://$serverName/Administrators”
 $Memberlist = @($Group.PSBase.Invoke(“Members”))
 $Members = $Memberlist |
 Return $Members

You use it simply by typing Get-LocalAdmins MYSERVER. Ain’t that neat?