Solved

get local administrators of domain members | powershell

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this Micro Tutorial viewers will learn how to restore their server from Bare Metal Backup image created with Windows Server Backup feature. As an example Windows 2012R2 is used.
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

839 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