how to find local admin group member

  • Thread starter Thread starter sks198117
  • Start date Start date
S

sks198117

Guest
cls




function






is-Member{



[






OutputType([bool])]



param






([parameter(Mandatory=$true)][string]$strcomputer,








[parameter(Mandatory=$true)][string]$memberName,








[parameter(Mandatory=$true)][string]$groupName)



$group






=[ADSI]"WinNT://$strcomputer/$groupName"




$alladmins






=@($group.Invoke("Members")) |%{$_.GetType().InvokeMember("Name",'GetProperty',$null,$_,$null)}



if






($alladmins-contains$memberName)


{




return$true}







else



{




return$false}




}



$servers






="indclr1"




foreach






($serverin$servers)


{


$memberName






="dosman"



$HashProps






=@{







'Name'=$server








'isAdminMember'=$false








'isRDPMember'=$false








'isRDPPortEnabled'=$false


}






write-host$server$membername







if(is-Member$server$memberName"Administrators") {$HashProps.isAdminMember =$true}







if(is-Member$server$memberName"Remote Desktop Users") {$HashProps.isRDPMember =$true}







$socket=New-ObjectNet.Sockets.TcpClient($CurrentComputer,3389);







if($socket.Connected)


{




$HashProps.isRDPPortEnabled =$true










$socket.Close()


}








New-Object-TypeName'PSCustomObject'-Property$HashProps|Select-Object@SelectHash



}



Continue reading...
 

Similar threads

Back
Top