Its been a while since I had posted something that is because my Laptop gave up on me. Anyways I’m back in action but still no laptop… Anyways I was tasked to get to list all websites that we had on the organization as we are implementing an Enterprise Architecture tool which need to be populated (the EA tool is called Troux). Now my dilemma is that I dont have anything on the desktop I have now, just a standard installation of OS and thats it so whats the best way to achieve the solution?
Aha!!!! Use the old school style vbs scripting.
So how do I achieve that? First is that you should know what are your servers and list them on a spreadsheet, In my case its good as we have it already pre-populated on the EA tool that we have so Ill just export it. So I have to create a code that will loop though that Spreadsheet and check what Websites are in there. Here is how I do it.
Set oExcel = CreateObject("Excel.Application") If (Err.Number <> 0) Then On Error GoTo 0 Wscript.Echo "You need to install an Excel Application" Wscript.Quit End If On Error GoTo 0 sExcelPath = "C:\Scripts\SERVERS-new.xls" ' Open Spreadsheet and Use First Worksheet. oExcel.WorkBooks.Open sExcelPath Set objSheet = oExcel.ActiveWorkbook.Worksheets(1) ' Loop through all the items in Speadsheet, 1st row is a Header Row intRow = 2 Do While objSheet.Cells(intRow, 1).Value <> "" strServerName = objSheet.Cells(intRow, 1).Value On Error Resume Next ' This takes care if you dont have IIS installed on the server Dim oW3SVC, oWebSite 'Get the IIS Server Object Set oW3SVC = GetObject("IIS://" & strServerName & "/W3SVC") If (Err <> 0) Then Else For Each oWebSite In oW3SVC If oWebSite.class = "IIsWebServer" Then Set oFile = CreateObject("Scripting.FileSystemObject") Set oTextFile = oFile.OpenTextFile("C:\Scripts\IIS.txt", 8, True) 'Get the Name of the Website oTextFile.WriteLine(strServerName & "," & oWebSite.ServerComment) oTextFile.Close Set oTextFile = Nothing Set oFile = Nothing End If Next End If intRow = intRow + 1 Loop ' Close Workbook and Excel. oExcel.ActiveWorkbook.Close oExcel.Application.Quit ' Clean up. Set oExcel = Nothing Set objSheet = Nothing Set objUser = Nothing Set oW3SVC = Nothing Set oWebSite = Nothing Wscript.Echo "Done"
Save it as [Filename].vbs and click the File then get your results. Simple yet effective specially when you have more than 200 websites on your organization, it saves your time jotting them down and you dont know you might discover new websites.