Quantcast
Viewing all articles
Browse latest Browse all 21975

Need to Query Local Admin Group

I wrote (copied) some PowerShell code that will add a Domain User to the Local Admin Group using ADSI.  

	$GuestPC = "WinNT://DOMAIN/UserName,user"
        $AdminGroup = [ADSI]("WinNT://"+$env:COMPUTERNAME+"/administrators,group")
	$AdminGroup.add($GuestPC)

         

I want to add an If - Else statement to check if the Domain User is already in the Administrators group.  

I found this code:

$members = @($AdminGroup.psbase.Invoke("Members"))
        $members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}

This code actually lists the members of the Administrators Group.  Maybe its early or I did not get enough sleep, but I cannot figure out how to just query the Administators group for $GuestPC and if it is there don't do anything, but if it is not there add it using the above code.  

Something easy for someone out there I hope?

Matt


Matt Dillon


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>