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.
This topic is 11 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
enjoyabhi@gmail.com
Posts: 14
Last visit: Sun Jan 22, 2012 2:09 am

vbscript to check SSl cert work in IIS6 nt in iis7

Post by enjoyabhi@gmail.com »



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
Last visit: Sun Jan 22, 2012 2:09 am

vbscript to check SSl cert work in IIS6 nt in iis7

Post by enjoyabhi@gmail.com »



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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra »

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra »

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

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra »

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
Last visit: Mon Sep 17, 2012 7:53 pm

vbscript to check SSl cert work in IIS6 nt in iis7

Post by sumitjain »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

vbscript to check SSl cert work in IIS6 nt in iis7

Post by jvierra »

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.
This topic is 11 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked