[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Retrieve Local Admins via Powershell

Posted on 2015-02-02
7
Medium Priority
?
90 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 12

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 12

Expert Comment

by:Tej Pratap Shukla ~Dexter
ID: 40583687
0
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!

 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 2000 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

649 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