Solved

get local administrators of domain members | powershell

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
A brief introduction to what I consider to be the best editor for PowerShell.
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 steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

679 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