• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 92
  • Last Modified:

Retrieve Local Admins via Powershell

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
Terellion
Asked:
Terellion
  • 3
  • 2
  • 2
2 Solutions
 
Tej Pratap Shukla ~DexterCommented:
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
 
TerellionAuthor Commented:
Hi there, thanks for that. Do you know how to filter this down though so it only shows certain users?
0
 
Tej Pratap Shukla ~DexterCommented:
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
SubsunCommented:
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
 
TerellionAuthor Commented:
Hi Subsun, thats brilliant! Is there a way to only show the ones that say Member - Yes? Thanks!
0
 
SubsunCommented:
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
 
TerellionAuthor Commented:
That is absolutely superb, works a treat THANK YOU! :)
0

Featured Post

Industry Leaders: 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!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now