Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

how to list local admins of in AD as a txt file which has a name as date of the day

$
0
0

Hello,

I have a script which lists local admins of all hosts in Active Directory:

$Searcher =New-ObjectDirectoryServices.DirectorySearcher([ADSI]"")
$Searcher.Filter="(objectClass=computer)"
$Computers =($Searcher.Findall())
md C:\All_Local_AdminsForeach($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}}

This script outputs HOST machine names as seperate txt files (HOST1.txt, HOST2.txt etc)

What I want is to get a single text file which name gets the date of the day (for example: 05082014.txt --> This file will include local admins of all hosts)

How should I modify above code to manage this?

Thank you very much.


Viewing all articles
Browse latest Browse all 15028

Trending Articles