Solved

get local administrators of domain members | powershell

Posted on 2014-12-24
4
235 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
  • 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
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…

759 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now