List the IIS Versions of your Webserver

By | April 9, 2010

This is in line with my post here as I am doing the Application Architecture Landscape for our Enterprise Architecture.  At one point I need to check what versions of IIS we are running in each server, so once again the easiest way for me is to just write a VBS Script to handle that.  Here is how it goes

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 = "D:Servers-STJOHN.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

 'Get the IIS Server Object
 Set objWMIService = GetObject("winmgmts:{authenticationLevel=pktPrivacy}\" & strServerName & "rootmicrosoftiisv2")
 If (Err <> 0) Then

 Else

 Set colItems = objWMIService.ExecQuery("Select * from IIsWebInfo")

 For Each objItem in colItems
 'Wscript.Echo "Major IIS Version Number: "  objItem.MajorIIsVersionNumber
 'Wscript.Echo "Minor IIS Version Number: "  objItem.MinorIIsVersionNumber
 'Wscript.Echo "Name: " & objItem.Name
 Set oFile = CreateObject("Scripting.FileSystemObject")
 Set oTextFile = oFile.OpenTextFile("D:IIS-Versions.txt", 8, True)
 oTextFile.WriteLine(strServerName & " - " & objItem.MajorIIsVersionNumber & "." & objItem.MinorIIsVersionNumber & " - " & objItem.Name)
 oTextFile.Close

 Set oTextFile = Nothing
 Set oFile = Nothing
 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"

Note : This is taking into consideration that you already know what are your servers and listed it on an Excel Spreadsheet


Leave a Reply