[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 311
  • Last Modified:

get local administrators of domain members | powershell

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
cmatchett
Asked:
cmatchett
  • 3
1 Solution
 
Joseph DalyCommented:
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
 
cmatchettAuthor Commented:
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
 
cmatchettAuthor Commented:
0
 
cmatchettAuthor Commented:
found what i was looking for
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now