vbscript to check SSl cert work in IIS6 nt in iis7

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
enjoyabhi@gmail.com
Posts: 14
Joined: Sat Oct 16, 2010 3:02 am

vbscript to check SSl cert work in IIS6 nt in iis7

Post by enjoyabhi@gmail.com » Mon May 09, 2011 5:35 pm



0Below is the script I was using to get the SSL certificate details IN IIS6 but this script is not working for iis7.What changes I have to make In order to make it working for IIS7? strComputer = "localhost" SET objService = GetObject( "IIS://" & strComputer & "/W3SVC") EnumServersites objService SUB EnumServersites( objSrv ) FOR Each objServer IN objSrv IF objServer.Class = "IIsWebServer" Then IF NOT Ubound(objServer.SecureBindings) = "-1" Then 'check to see if there is at least one securebinding WScript.Echo "Site ID = " & objServer.Name & VbCrLf & "Comment = """ & objServer.ServerComment wscript.Echo "SSL Certificate Expiration Date: " & GetSSLExpirationDate(objServer.Name) wscript.Echo "Days Remaining: " & DaysRemaining(GetSSLExpirationDate(objServer.Name)) wscript.echo vbcrlf & "-----------------------------" & vbcrlf END IF END IF strBindings = "" Next END Sub FUNCTION GetSSLExpirationDate( strSiteID ) Set iiscertobj = WScript.CreateObject("IIS.CertObj") iiscertobj.serverName = "localhost" iiscertobj.InstanceName = "W3SVC/" & strSiteID tmpArray = Split(iiscertobj.GetCertInfo,vbLf) For Each x in tmpArray If Left(x,2) = "6=" Then GetSSLExpirationDate = Mid(x,3,len(x)-2) End If Next END FUNCTION Function DaysRemaining(strdate) If IsDate(strDate) Then strdate = cDate(strdate) End If DaysRemaining = DateDiff("d",Date,strdate) End Function

User avatar
enjoyabhi@gmail.com
Posts: 14
Joined: Sat Oct 16, 2010 3:02 am

vbscript to check SSl cert work in IIS6 nt in iis7

Post by enjoyabhi@gmail.com » Mon May 09, 2011 5:35 pm



0Below is the script I was using to get the SSL certificate details IN IIS6 but this script is not working for iis7.What changes I have to make In order to make it working for IIS7? strComputer = "localhost" SET objService = GetObject( "IIS://" & strComputer & "/W3SVC") EnumServersites objService SUB EnumServersites( objSrv ) FOR Each objServer IN objSrv IF objServer.Class = "IIsWebServer" Then IF NOT Ubound(objServer.SecureBindings) = "-1" Then 'check to see if there is at least one securebinding WScript.Echo "Site ID = " & objServer.Name & VbCrLf & "Comment = """ & objServer.ServerComment wscript.Echo "SSL Certificate Expiration Date: " & GetSSLExpirationDate(objServer.Name) wscript.Echo "Days Remaining: " & DaysRemaining(GetSSLExpirationDate(objServer.Name)) wscript.echo vbcrlf & "-----------------------------" & vbcrlf END IF END IF strBindings = "" Next END Sub FUNCTION GetSSLExpirationDate( strSiteID ) Set iiscertobj = WScript.CreateObject("IIS.CertObj") iiscertobj.serverName = "localhost" iiscertobj.InstanceName = "W3SVC/" & strSiteID tmpArray = Split(iiscertobj.GetCertInfo,vbLf) For Each x in tmpArray If Left(x,2) = "6=" Then GetSSLExpirationDate = Mid(x,3,len(x)-2) End If Next END FUNCTION Function DaysRemaining(strdate) If IsDate(strDate) Then strdate = cDate(strdate) End If DaysRemaining = DateDiff("d",Date,strdate) End Function

User avatar
jvierra
Posts: 13506
Joined: Tue May 22, 2007 9:57 am
Contact:

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra » Mon May 09, 2011 5:53 pm

You need to install the admin support modules for this to work. In WS2008 and later these modules are not installed by ferfault as they are in WS2003.


User avatar
jvierra
Posts: 13506
Joined: Tue May 22, 2007 9:57 am
Contact:

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra » Tue May 10, 2011 5:25 am

WHat do you mewna by 'it's not working'? Is there some kind of message? Do you get an error?


User avatar
jvierra
Posts: 13506
Joined: Tue May 22, 2007 9:57 am
Contact:

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra » Tue May 10, 2011 6:49 am

I had some time to run this against a cuople of IIS7 sites.

The code works correctly and enumerates all sites with certificates. If no sites have certs then the code produces NO output.

I have tested it both locally and remotely with no problems.

I suspect you either have not installed any certs or you have not installed all of teh required support components on the target machine. These components must be installed on the 'target' IIS server not on the one you are running the script from.

User avatar
sumitjain
Posts: 1
Joined: Mon Sep 17, 2012 7:53 pm

vbscript to check SSl cert work in IIS6 nt in iis7

Post by sumitjain » Mon Sep 17, 2012 3:38 pm

The script you are trying to use is compatible with IIS6 to make it run in IIS 7 you need to install the IIS6 Management compatiblity .

Follow the steps to install:

Go to mycomputer-> right Click-> Mange
Under Server Manager -> Roles-> Click on Roles-> On the right window check Web server-> Role services-> Search for IIS6 Management compatiblity and install.

Also install all the IIS 6 compatibilty services .

Once done, try to run the above script it will work

User avatar
jvierra
Posts: 13506
Joined: Tue May 22, 2007 9:57 am
Contact:

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra » Mon Sep 17, 2012 11:42 pm

Hi sumitjain - welcome to Sapien/ScriptingAnswers

Did you see that there is already a link to that information given above. This is also a very old thread.

http://learn.iis.net/page.aspx/125/meta ... ith-iis-7/

This is the page that describes the how and why of installing the compatibility bits. Th elinkalso comntains other useful information on other things that are updated and made available besides just the IIS 6 view. It is worth a read.

Locked