?
Solved

get local administrators of domain members | powershell

Posted on 2014-12-24
4
Medium Priority
?
300 Views
Last Modified: 2015-01-10
Hi experts !,

I would like the export of this to be a single CSV.  Currently the export is a single txt file for each server listing the members of the local administrators group.

# This script uses Powershell to query members of Local Administrators group on every machine.

$Searcher = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$Searcher.Filter = "(objectClass=computer)"
$Computers = ($Searcher.Findall())
md C:\All_Local_Admins
Foreach ($Computer in $Computers)
{
$Path=$Computer.Path
$Name=([ADSI]"$Path").Name
write-host $Name
$members =[ADSI]"WinNT://$Name/Administrators"
$members = @($members.psbase.Invoke("Members"))
$members | foreach {$_.GetType().InvokeMember("Name", 'GetProperty',
$null, $_, $null) | out-file -append C:\All_Local_Admins\$name.txt
}

}
0
Comment
Question by:cmatchett
[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
4 Comments
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 40516577
Since they are using the out-file append option i believe it would pretty simple changing the variable $name.txt to a hard coded name.

I.E.
$null, $_, $null) | out-file -append C:\All_Local_Admins\$name.txt

$null, $_, $null) | out-file -append C:\All_Local_Admins\somefile.txt
0
 

Author Comment

by:cmatchett
ID: 40516586
yes, that puts everything in one file and it doesn't give the server name beside the group members.  it just lists everything in one big list
0
 

Accepted Solution

by:
cmatchett earned 0 total points
ID: 40516630
0
 

Author Closing Comment

by:cmatchett
ID: 40541807
found what i was looking for
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
This tutorial will walk an individual through the process of installing of Data Protection Manager on a server running Windows Server 2012 R2, including the prerequisites. Microsoft .Net 3.5 is required. To install this feature, go to Server Manager…

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