<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.iis.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:cs="http://blogs.iis.net/"><channel><title>Sukesh&amp;#39;s IIS Blog : IIS</title><link>http://blogs.iis.net/sukesh/archive/tags/IIS/default.aspx</link><description>Tags: IIS</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>How to Check certificate expiry for webserver (IIS) certificates using script</title><link>http://blogs.iis.net/sukesh/archive/2007/09/12/how-to-check-certificate-expiry-for-webserver-iis-certificates-using-script.aspx</link><pubDate>Thu, 13 Sep 2007 02:40:00 GMT</pubDate><guid isPermaLink="false">50bcf3b4-f6fe-4638-adff-0c150e922e99:2241605</guid><dc:creator>sukesh</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://blogs.iis.net/sukesh/rsscomments.aspx?PostID=2241605</wfw:commentRss><comments>http://blogs.iis.net/sukesh/archive/2007/09/12/how-to-check-certificate-expiry-for-webserver-iis-certificates-using-script.aspx#comments</comments><description>&lt;P&gt;Although the title says webserver certificates the script is not limited to webserver certificates only.&lt;/P&gt;
&lt;P&gt;This script is useful for admins to check expiry dates of server certificates and be prepared to renew or change them. In case if you have ideas of using this in your server environment and you need help in tweaking this script do let me know.&lt;/P&gt;
&lt;P&gt;Please copy &amp;amp; paste script below into a file called "CertExpiryCheck.vbs" and run the script from command line like&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color=#0000ff&gt;C:\&amp;gt; cscript certexpirycheck.vbs [SubjectName]&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;C:\&amp;gt; cscript certexpirycheck.vbs sukak&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/sukeshak/WindowsLiveWriter/HowtoCheckcertificateexpiryforwebserverc_98F4/CertExpirycheck.jpg" mce_href="http://blogs.msdn.com/blogfiles/sukeshak/WindowsLiveWriter/HowtoCheckcertificateexpiryforwebserverc_98F4/CertExpirycheck.jpg"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=65 alt=CertExpirycheck src="http://blogs.msdn.com/blogfiles/sukeshak/WindowsLiveWriter/HowtoCheckcertificateexpiryforwebserverc_98F4/CertExpirycheck_thumb.jpg" width=480 border=0 mce_src="http://blogs.msdn.com/blogfiles/sukeshak/WindowsLiveWriter/HowtoCheckcertificateexpiryforwebserverc_98F4/CertExpirycheck_thumb.jpg"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;* here "sukak" is subject name which usually would be your domain name (FQDN)&lt;BR&gt;* Issued by also shows "sukak" in my case since the test was done using self issued certificate created using selfSSL.exe&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;PRE style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; FONT-SIZE: 8pt; PADDING-BOTTOM: 0px; MARGIN: 0em; OVERFLOW: visible; WIDTH: 100%; COLOR: black; BORDER-TOP-STYLE: none; LINE-HEIGHT: 12pt; PADDING-TOP: 0px; FONT-FAMILY: consolas, 'Courier New', courier, monospace; BORDER-RIGHT-STYLE: none; BORDER-LEFT-STYLE: none; BACKGROUND-COLOR: #f4f4f4; BORDER-BOTTOM-STYLE: none"&gt;&lt;SPAN style="COLOR: #008000"&gt;'**************************************************&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #008000"&gt;'* CertExpiryCheck.vbs&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #008000"&gt;'* Enumerate certificates with day left for expiry &lt;/SPAN&gt;
&lt;SPAN style="COLOR: #008000"&gt;'**************************************************&lt;/SPAN&gt;

&lt;SPAN style="COLOR: #0000ff"&gt;Option&lt;/SPAN&gt; Explicit
&lt;SPAN style="COLOR: #0000ff"&gt;Dim&lt;/SPAN&gt; SubjectName
&lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt; WScript.Arguments.Count &amp;gt; 0 &lt;SPAN style="COLOR: #0000ff"&gt;Then&lt;/SPAN&gt;
    SubjectName = LCase(WScript.Arguments(0))
&lt;SPAN style="COLOR: #0000ff"&gt;Else&lt;/SPAN&gt;
    CommandUsage
&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt;

&lt;SPAN style="COLOR: #0000ff"&gt;Dim&lt;/SPAN&gt; Store, Certificates, Certificate
&lt;SPAN style="COLOR: #0000ff"&gt;Const&lt;/SPAN&gt; CAPICOM_LOCAL_MACHINE_STORE = 1
&lt;SPAN style="COLOR: #0000ff"&gt;Const&lt;/SPAN&gt; CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME = 1        
&lt;SPAN style="COLOR: #0000ff"&gt;Const&lt;/SPAN&gt; CAPICOM_STORE_OPEN_READ_ONLY = 0

&lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt; Store = CreateObject(&lt;SPAN style="COLOR: #006080"&gt;"CAPICOM.Store"&lt;/SPAN&gt;)
Store.Open CAPICOM_LOCAL_MACHINE_STORE, &lt;SPAN style="COLOR: #006080"&gt;"MY"&lt;/SPAN&gt; ,CAPICOM_STORE_OPEN_READ_ONLY
&lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt; Certificates = Store.Certificates.Find(CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, SubjectName, 0)

&lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt; Certificates.Count &amp;gt;0 &lt;SPAN style="COLOR: #0000ff"&gt;Then&lt;/SPAN&gt;
   &lt;SPAN style="COLOR: #0000ff"&gt;For&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;Each&lt;/SPAN&gt; Certificate &lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt; Certificates
    &lt;SPAN style="COLOR: #008000"&gt;'Certificate.display()    'If you want to see the Cert in UI&lt;/SPAN&gt;
    WScript.Echo &lt;SPAN style="COLOR: #006080"&gt;"*** Subject "&lt;/SPAN&gt; &amp;amp; Certificate.SubjectName &amp;amp; &lt;SPAN style="COLOR: #006080"&gt;" ***"&lt;/SPAN&gt;
    WScript.Echo &lt;SPAN style="COLOR: #006080"&gt;"Issued by "&lt;/SPAN&gt; &amp;amp; Certificate.IssuerName 
    WScript.Echo &lt;SPAN style="COLOR: #006080"&gt;"Valid from "&lt;/SPAN&gt; &amp;amp; Certificate.ValidFromDate &amp;amp; &lt;SPAN style="COLOR: #006080"&gt;" to "&lt;/SPAN&gt; &amp;amp; Certificate.ValidToDate 
    WScript.Echo &lt;SPAN style="COLOR: #006080"&gt;"Days to expiry "&lt;/SPAN&gt; &amp;amp; DateDiff(&lt;SPAN style="COLOR: #006080"&gt;"d"&lt;/SPAN&gt;,now(),Certificate.ValidToDate)
    WScript.Echo 
   &lt;SPAN style="COLOR: #0000ff"&gt;Next&lt;/SPAN&gt;
 &lt;SPAN style="COLOR: #0000ff"&gt;Else&lt;/SPAN&gt;
  WScript.Echo &lt;SPAN style="COLOR: #006080"&gt;"No certificates with SubjectName =&amp;gt; '"&lt;/SPAN&gt; &amp;amp; SubjectName &amp;amp; &lt;SPAN style="COLOR: #006080"&gt;"'"&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;If&lt;/SPAN&gt;

&lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt; Certificates = &lt;SPAN style="COLOR: #0000ff"&gt;Nothing&lt;/SPAN&gt;
&lt;SPAN style="COLOR: #0000ff"&gt;Set&lt;/SPAN&gt; Store = &lt;SPAN style="COLOR: #0000ff"&gt;Nothing&lt;/SPAN&gt;

&lt;SPAN style="COLOR: #0000ff"&gt;Sub&lt;/SPAN&gt; CommandUsage
  MsgBox &lt;SPAN style="COLOR: #006080"&gt;"Usage: CertExpiryCheck.vbs  [SubjectName] "&lt;/SPAN&gt;, vbInformation,&lt;SPAN style="COLOR: #006080"&gt;"CertExpiryCheck"&lt;/SPAN&gt;
  WScript.Quit(1)
&lt;SPAN style="COLOR: #0000ff"&gt;End&lt;/SPAN&gt; Sub&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just keep in mind you need capicom.dll to use this script. This comes default on Windows 2003 (I guess) but might need to be downloaded and registered on other platforms like Vista. Use &lt;STRONG&gt;regsvr32 capicom.dll &lt;/STRONG&gt;to register it first before using the script.&lt;/P&gt;&lt;img src="http://blogs.iis.net/aggbug.aspx?PostID=2241605" width="1" height="1"&gt;</description><category domain="http://blogs.iis.net/sukesh/archive/tags/Certificate/default.aspx">Certificate</category><category domain="http://blogs.iis.net/sukesh/archive/tags/IIS/default.aspx">IIS</category></item></channel></rss>