powershell - Check if user is a member of the local admins group on a remote server -


the user member of ad security group "domain\sql admins", , security group "domain\sql admins" member of local administrators group on windows server.

i have tried following powershell script:

 $u = "username"; net localgroup administrators | {$_ -match $u} 

this script return user if added directly admin group. have cycle through of groups in admin group until find user? or there way?

check out article, boe prox on microsoft hey scripting guy blog. describes how check if user local administrator or not.

http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/11/check-for-admin-credentials-in-a-powershell-script.aspx

this article points test-isadmin function posted onto technet gallery.

http://gallery.technet.microsoft.com/scriptcenter/1b5df952-9e10-470f-ad7c-dc2bdc2ac946

the function contains following code, returns $true or $false.

([security.principal.windowsprincipal] [security.principal.windowsidentity]::getcurrent()).isinrole([security.principal.windowsbuiltinrole] "administrator") 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -