I have been trying to improve my scripting capabilities in the hopes of reducing some of my workload supporting various systems, and determined learning powershell would be the best way to go versus refreshing my knowledge of batch scripts or vbscript.
I picked up a great book called Learn Windows Powershell in a Month of Lunches and it is the perfect book for a beginner like myself. I had originall picked up a copy of O’Reilly’s Windows Powershell Cookbook but I found it was not appropriate for someone learning the language, but I can see it will be extremely useful once I know what I am doing!
One of my first real life goals to accomplish was to find an easy way to search for SSL certificates that were due to expire on servers. I found some information online, including some incredibly long vbscripts and even some long powershell scripts. I find that powershell’s strength is its object oriented nature, and that you can pipe objects from one cmdlet to another without having to add alot of programming logic to your script.
I ended up tweaking some code I found online and came up with a single line to output all the SSL certificates I installed on a server that are set to expire in the next 30 days. It seems weird calling a single line script code, but ah well what are you gonna do?
dir cert:\LocalMachine\My -rec | Select-Object | Where-Object {$_.NotAfter -lt (get-date).AddDays(30)}
I was very pleased with the result! I would probably need to some more coding to set this thing to email me the server name and the certificate info if its going to expire, but its a great start!
Leave a Reply