It's been a while since I posted something, that is because my laptop gave up on me. Anyways, I'm back in action but still no laptop… I was tasked to get to list all websites that we had on the organization as we are implementing an Enterprise Architecture tool which needs to be populated (the EA tool is called Troux). Now my dilemma is that I don't have anything on the desktop I have now, just a standard installation of OS and that's it! So what's 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 your servers are and list them on a spreadsheet. In my case, it's good as we have it already pre-populated on the EA tool that we have, so I'll 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"
oExcel.WorkBooks.Open sExcelPath
Set objSheet = oExcel.ActiveWorkbook.Worksheets(1)
intRow = 2
Do While objSheet.Cells(intRow, 1).Value <> ""
strServerName = objSheet.Cells(intRow, 1).Value
On Error Resume Next
Dim oW3SVC, oWebSite
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)
oTextFile.WriteLine(strServerName & "," & oWebSite.ServerComment)
oTextFile.Close
Set oTextFile = Nothing
Set oFile = Nothing
End If
Next
End If
intRow = intRow + 1
Loop
oExcel.ActiveWorkbook.Close
oExcel.Application.Quit
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, especially when you have more than 200 websites on your organization, it saves you time jotting them down and you never know you might discover new websites.