Hello,
I have a script which lists local admins of all hosts in Active Directory:
$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
}
}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.