If for some reason they are unable or unwilling to block sites via DNS
(as in my organization) here's the script that I use to push out a
hosts file.
This script assumes that your hosts file is on the root of c. Also
modify the line as specified below to match your computer object
locations.
Watch for word wrap
--------------------------------------------------------------------------
Const ADS_SCOPE_SUBTREE = 2
Const OverWriteFiles = True
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.Properties("Sort On") = "Name"
objCommand.Properties("Page Size") = 2000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
' Change the line below to match the location of your computer objects
objCommand.CommandText = _
"Select Name, Location from
'LDAP://ou=someou,dc=somedc,dc=someotherdc' " _
& "Where objectClass='computer'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
i = 0
Set objComputerList = CreateObject("Scripting.Dictionary")
Do Until objRecordSet.EOF
objComputerList.Add i, objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
i = i + 1
Loop
On Error Resume Next
Set objShell = CreateObject("WScript.Shell")
j = 0
For Each objItem in objComputerList
strDestinationComputer = objComputerList.Item(objItem)
strComputer = objComputerList.Item(objItem)
Wscript.Echo "Attempting: " & strComputer, date, time
Set objWshScriptExec = objShell.Exec("ping " & strComputer & " -n 1")
Set objStdOut = objWshScriptExec.StdOut
For j = 1 To 3
strLine = objStdOut.ReadLine
Next
strLine = objStdOut.ReadLine
If instr(strLine, "Reply") Then
Wscript.Echo "Copying " & strComputer, date, time
Wscript.Echo
Err.Clear
Destination = "\\" & strDestinationComputer &
"\C$\WINNT\System32\Drivers\etc\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\hosts" , Destination , OverWriteFiles
Else
Err.Clear
Wscript.Echo "Could not ping " & strcomputer, date, time
Wscript.Echo
End If
Next
Michael Reese
Information Systems Technician