This will return you local administrators (another answer is probably better suited here):
$group =[ADSI]"WinNT://./Administrators" $members = @($group.psbase.Invoke("Members")) $admins = $members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
And this will check the credentials:
Add-Type -assemblyname system.DirectoryServices.accountmanagement $DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine) $DS.ValidateCredentials("test", "password")
All you have to do is verify that the credentials are in order and that the user is a member of the Admins group
Andrey Marchuk
source share