# encoding: ascii # api: powershell # title: # description: retrieves local administrators of a maschine using System.DirectoryServices.AccountManagement via Well-known security identifiers # version: 0.1 # type: function # license: CC0 # function: get-localadministrators # x-poshcode-id: 4854 # x-archived: 2014-04-09T11:52:53 # # function get-localadministrators { param ([string]$computername=$env:computername) $computername = $computername.toupper() Add-Type -AssemblyName System.DirectoryServices.AccountManagement $PrincipalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine, $Computer) $GroupPrincipal = New-Object System.DirectoryServices.AccountManagement.GroupPrincipal($PrincipalContext) $Searcher = New-Object System.DirectoryServices.AccountManagement.PrincipalSearcher $Searcher.QueryFilter = $GroupPrincipal $objoutput = $Searcher.FindAll() | where {$_.Sid -eq 'S-1-5-32-544'} # Administrators group - http://support.microsoft.com/kb/243330 #StructuralObjectClass=user #StructuralObjectClass=group #ContextType = Domain #ContextType = Machine return $objoutput }#end function