'======================================================================================================== '======================================================================================================== ' ### Script: footerscan.vbs ' ### Created: 06/25/04 ' ### Group: AHS ' ### Contact: tim @ blackpondfarm.com ' ### Description: Scans server list for footer settings '======================================================================================================== '======================================================================================================== 'Option Explicit On Error Resume Next 'Set our variables Dim WshShell,Wshnetwork,Wshfile Dim strServer Dim strinputFile Dim stroutputFile Dim INST Dim Index,Path Dim objArgs 'Set up our environment Set WshShell = WScript.CreateObject("WScript.Shell") Set Wshnetwork = wscript.CreateObject("Wscript.Network") Set Wshfile = wscript.CreateObject("Scripting.FileSystemObject") 'Check to ensure we're using cscript If InStr(1, wscript.fullname, "cscript.exe", 1) = 0 Then If Err.number <> 0 Then Err.Clear temp = Wshshell.Run("cmd /c ""cscript //h:cscript //nologo //s""", 0, True) temp = MsgBox("The script has changed the default output " & _ "of Windows Scripting Host to the command prompt." & _ vbCrLf & "This is pop up is normal, just re-run the " & _ "script!", 0, "WSH default changed to cscript.") wscript.quit END IF 'Get our arguments Set objArgs = WScript.Arguments IF objArgs.Count = 2 THEN strInputFile = objArgs(0) strOutputFile = objArgs(1) Else wscript.echo "Usage: footerscan.vbs inputfile outputfile" wscript.echo "" wscript.echo "Example: footerscan.vbs servers.txt results.txt" wscript.echo "" wscript.echo "This will read server names from an input file and scan" wscript.echo "each server's web sites for any instances of a document footer" wscript.echo "" wscript.quit End If 'Clear out any existing output file If (Wshfile.fileexists(strOutputFile)) Then Wshfile.deletefile(strOutputFile) 'Open input file, call scan with each servername Set wshtempfile = wshfile.OpenTextFile(strInputFile, 1) Do While wshtempfile.AtEndOfStream <> true strServer = ucase(wshtempFile.ReadLine) IF LEFT(strServer,2) = "\\" THEN strServer = mid(strServer,3) scan(strServer) Loop wshInputFile.Close wscript.DisconnectObject wshInputFile wscript.quit '======================================================================================================== '======================================================================================================== Function scan(strServer) On error resume next Dim bDone,Footer,Site,Enabled,vDir Screenout "Scanning " & strServer & "..." ' Grab the web service object Set Path = GetObject("IIS://" & strServer & "/w3svc") If Err.Number <> 0 Then Screenout " Unable to access web services on " & strServer wscript.echo " Ensure you have Admin permissions and that the server is online." exit function End If Index = 1 bDone = False ' test successive numbers under w3svc until an unoccupied slot is found While (Not bDone) Err.Clear Set SiteObj = GetObject("IIS://" & strServer & "/w3svc/" & Index) If (Err.Number = 0) Then ' A web server is defined at this position so scan and then increment dim Path Set IISPath = GetObject("IIS://" & strServer & "/w3svc/" & index & "/ROOT") Enabled = IISPath.EnableDocFooter Footer = IISPath.DefaultDocFooter Site = IISPath.AppFriendlyName IF Enabled <> 0 THEN Screenout " SERVER:" & strServer & " SITE:" & site & " FOOTER:" & Footer FOR EACH vDir in IISPath Enabled = vDir.EnableDocFooter Footer = vDir.DefaultDocFooter Site = vDir.Name IF Enabled <> 0 THEN Screenout " SERVER:" & strServer & " VDIR:" & Site & " FOOTER:" & Footer next Index = Index + 1 Else bDone = True End If Wend Screenout "Finished scanning " & strServer Screenout "" END FUNCTION '======================================================================================================== '======================================================================================================== Function screenout(text) Dim wsherrorlogfile On Error Resume Next If (Wshfile.fileexists(strOutputFile)) Then 'If our output file exists, open it, write our data, and close Set wsherrorlogfile = Wshfile.OpenTextFile(strOutputFile, 8) wsherrorlogfile.writeline (text) wscript.echo(text) wsherrorlogfile.Close wscript.DisconnectObject wsherrorlogfile Set wsherrorlogfile = Nothing If Err.number <> 0 Then Err.Clear Else 'File doesn't yet exist, create our output file and write our first line of text Set wsherrorlogfile = Wshfile.createtextfile(strOutputFile, 1) wsherrorlogfile.writeline (text) wscript.echo(text) wsherrorlogfile.Close wscript.DisconnectObject wsherrorlogfile Set wsherrorlogfile = Nothing If Err.number <> 0 Then Err.Clear End If End Function '======================================================================================================== '========================================================================================================