<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/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/"><channel><title>Search results for 'app:weblogs' matching tags 'Windows PowerShell', 'security', and 'certificates'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Windows+PowerShell,security,certificates&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Windows PowerShell', 'security', and 'certificates'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>Use PowerShell to Find Certificates that are About to Expire</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2013/03/05/use-powershell-to-find-certificates-that-are-about-to-expire.aspx</link><pubDate>Tue, 05 Mar 2013 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:21971</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to find certificates that are about to expire.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/q-sm.jpg" alt="Hey, Scripting Guy! Question" /&gt;&amp;nbsp;Hey, Scripting Guy! We recently implemented an internal certification authority that we use for various scenarios, such as issuing code-signing certificates for our developers and certain admins as well as for user authentication scenarios. Now, of course, we have a problem. My pointy headed boss is worried that people with certificates will not renew them properly, so he wants me to write a script that can find out when scripts are about to expire. Is this something that I can do easily?&lt;/p&gt;
&lt;p&gt;&amp;mdash;AR&lt;/p&gt;
&lt;p&gt;&lt;img src="http://img.microsoft.com/library/media/1033/technet/images/scriptcenter/qanda/a-sm.jpg" alt="Hey, Scripting Guy! Answer" /&gt;&amp;nbsp;Hello AR,&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. Today is Tuesday, and the Scripting Wife and I are on the road for a bit. Luckily, Windows 8 phone easily sets up as a modem, and I can connect to the Internet with my laptop and check my email at scripter@microsoft.com. It is cool. The bad thing about a road trip is that it is nearly impossible to get a decent cup of tea. I made a pot before we left, so I have some decent tea&amp;mdash;at least for a little while.&lt;/p&gt;
&lt;p&gt;AR, dude, this is so easy&amp;hellip;&lt;/p&gt;
&lt;p&gt;The reason it is so easy to find certificates that are about to expire in Windows PowerShell 3.0 is because we add a dynamic parameter to the &lt;strong&gt;Get-ChildItem&lt;/strong&gt; cmdlet when the cmdlet targets the Cert: PSDrive. The dynamic parameter is called &lt;strong&gt;&amp;ndash;ExpiringInDays&lt;/strong&gt;&lt;em&gt; &lt;/em&gt;and it does exactly what you might think it would do&amp;mdash; it reports certificates that are going to expire within a certain time frame. To find certificates that will expire within 75 days, use the command shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-ChildItem -Path cert: -Recurse -ExpiringInDays 75&lt;/p&gt;
&lt;p&gt;The command and the output associated with the command to find certificates that expire in 75 days are shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5164.HSG_2D00_3_2D00_5_2D00_13_2D00_01.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5164.HSG_2D00_3_2D00_5_2D00_13_2D00_01.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I do not have to set my working location to the Cert: PSDrive, because I can specify it as the path of the &lt;strong&gt;Get-ChildItem&lt;/strong&gt; cmdlet. If I need to perform more than one or two operations, I will change my working location to the Cert: PSDrive to simplify some of the typing requirements. To change to the Cert: PSDrive, I use the &lt;strong&gt;Set-Location&lt;/strong&gt; cmdlet (&lt;strong&gt;SL&lt;/strong&gt; is an alias, as is &lt;strong&gt;CS&lt;/strong&gt;). This technique is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS C:\&amp;gt; sl cert:&lt;/p&gt;
&lt;p&gt;After I have changed my working location to the Cert: PSDrive, the Windows PowerShell prompt (by default) changes to include the Cert: drive location as shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;PS Cert:\&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;Finding about to expire certificates the PowerShell 2.0 way&lt;/h2&gt;
&lt;p&gt;If you are using Windows PowerShell 2.0 (or if you just like to type), you can still find certificates that are about to expire by using the &lt;strong&gt;Get-ChildItem&lt;/strong&gt; cmdlet on your Cert: PSDrive, and then piping the results to the &lt;strong&gt;Where-Object&lt;/strong&gt;. You need to filter on the &lt;strong&gt;NotAfter &lt;/strong&gt;property of the returned certificate object. The great thing is that Windows PowerShell makes it easy to work with dates. I use the &lt;strong&gt;AddDays&lt;/strong&gt; method from the &lt;strong&gt;DateTime &lt;/strong&gt;object that is returned by the &lt;strong&gt;Get-Date&lt;/strong&gt; cmdlet.&lt;/p&gt;
&lt;p&gt;To gain access to the &lt;strong&gt;AddDays&lt;/strong&gt; method, I group the &lt;strong&gt;Get-Date&lt;/strong&gt; cmdlet first. Each certificate object crosses the pipeline to the &lt;strong&gt;Where-Object&lt;/strong&gt; cmdlet. Inside the script block for the &lt;strong&gt;Where-Object&lt;/strong&gt;, I look at the &lt;strong&gt;NotAfter &lt;/strong&gt;property, and I check to see if it is less than a date that is 75 days in the future. Upon finding the certificates that have an expiration date of less than 75 days in the future, I send the results to the &lt;strong&gt;Select-Object&lt;/strong&gt; cmdlet, where I choose the thumbprint and the subject. The following command returns certificates that have an expiration date that is before 75 days in the future.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-ChildItem -Recurse | where { $_.notafter -le (get-date).AddDays(75) } | select thumbprint, subject&lt;/p&gt;
&lt;p&gt;When I run the command, the results do not compare very well with those from the previous command. The command and its resulting output are shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1018.HSG_2D00_3_2D00_5_2D00_13_2D00_02.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1018.HSG_2D00_3_2D00_5_2D00_13_2D00_02.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The reason the output is different is because the new &lt;strong&gt;ExpiringInDays&lt;/strong&gt;&lt;em&gt; &lt;/em&gt;parameter for Windows PowerShell 3.0 does not include already expired certificates. Windows ships with expired certificates because certain executables that have been signed with a certificate, but have not been resigned with a new certificate, need the old certificate to ensure the validity of the certificate.&lt;/p&gt;
&lt;p&gt;By modifying the command so it also filters out expired certificates, the results on my computer become the same. Here is the revised command.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Get-ChildItem -Recurse | where { $_.notafter -le (get-date).AddDays(75) -AND $_.notafter -gt (get-date)} | select thumbprint, subject&lt;/p&gt;
&lt;p&gt;The command and the output associated with the command are shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0160.HSG_2D00_3_2D00_5_2D00_13_2D00_03.png"&gt;&lt;img title="Image of command output" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/0160.HSG_2D00_3_2D00_5_2D00_13_2D00_03.png" alt="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;AR, that is all there is to using the certificate provider in Windows PowerShell to find certificates that will expire in a certain time frame. Join me tomorrow when I will talk about more cool stuff.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ed Wilson, Microsoft Scripting Guy&lt;/strong&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3555305" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell and .NET to Find Expired Certificates</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/02/16/use-powershell-and-net-to-find-expired-certificates.aspx</link><pubDate>Wed, 16 Feb 2011 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:9364</guid><dc:creator>Anonymous</dc:creator><description>Summary : Learn how to use Windows PowerShell and Microsoft .NET classes to find expired certificates on local and remote computers. Hey, Scripting Guy! How can I use Windows PowerShell and the .NET Framework classes to work with certificates? -- PB Hello...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/16/use-powershell-and-net-to-find-expired-certificates.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3386232" width="1" height="1" alt="" /&gt;</description></item></channel></rss>