Solved

Retrieve Local Admins via Powershell

Posted on 2015-02-02
7
87 Views
Last Modified: 2015-02-02
Hey guys, i'd like a script to run to retrieve the list of local Administrators of a group of servers but only match certain users.

So something like

(Get-WMIObject Win32_Group | Where-Object { $_.Name –eq ‘Administrators’ }).GetRelated() | Where-Object { $_.__CLASS –eq “Win32_UserAccount” –or $_.__CLASS –eq “Win32_Group” } | Select-Object __CLASS,Caption,SID


But have a where-object that includes a certain user (just so we can identify if a user has local admin to any server.

Thanks for your help :)
0
Comment
Question by:Terellion
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 11

Expert Comment

by:Tej Pratap Shukla ~Dexter
ID: 40583654
Hi..

Follow the link for script to retrive local admins

http://andrewmorgan.ie/2011/06/retrieve-a-list-of-local-administrators-using-powershell/

Thanks
Dexter
0
 

Author Comment

by:Terellion
ID: 40583684
Hi there, thanks for that. Do you know how to filter this down though so it only shows certain users?
0
 
LVL 11

Expert Comment

by:Tej Pratap Shukla ~Dexter
ID: 40583687
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 500 total points
ID: 40583713
To find whether a user is member of a local admin group you can use following function..
Function Get-localadmin ($Comp,$User){
$group =[ADSI]"WinNT://$Comp/Administrators"
$Member = @($group.psbase.Invoke("Members")) | % {
	 $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
	} |?{$_ -eq $User}
 If ($Member){
	  New-Object PSObject -Property @{
	  Server = $Comp
	  Member = "Yes"
	  }
  }Else{
  New-Object PSObject -Property @{
  Server = $Comp
  Member = "No"
  }
  }
 }

Open in new window

So to check against single server
Get-localadmin -Comp ServerA -User UserA 

Open in new window

To check against a list of servers..
GC Server.txt | %{
Get-localadmin -Comp $_ -User UserA
}

Open in new window

0
 

Author Comment

by:Terellion
ID: 40583718
Hi Subsun, thats brilliant! Is there a way to only show the ones that say Member - Yes? Thanks!
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40583725
Function usage is same as shown in above comment..
Function Get-localadmin ($Comp,$User){
$group =[ADSI]"WinNT://$Comp/Administrators"
$Member = @($group.psbase.Invoke("Members")) | % {
	 $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
	} |?{$_ -eq $User}
 If ($Member){
	  New-Object PSObject -Property @{
	  Server = $Comp
	  Member = "Yes"
	  }
  }
 }

Open in new window

0
 

Author Comment

by:Terellion
ID: 40583732
That is absolutely superb, works a treat THANK YOU! :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question