Converting Timespans to Repetition Patterns

Over on, I’ve recently published a followup article about creating daily or weekly scheduled PowerShell jobs that support a repetition interval. The short answer is to use the Scheduled Tasks cmdlets. In the Petri article I talk about needing to use a special string format for the timespan. It is documented on MSDN.

It isn’t especially difficult to work it out, but I thought it would be handy to have a PowerShell function to convert a timespan to this format.

Technically, the pattern will support any timespan but since the pattern used with scheduled tasks must be between 1 minute and 31 days, I added that as a validation parameter. The function simply builds the final string based on the number of date time elements, i.e. hours, minutes and seconds.

Hopefully this function makes it easier to automate the scheduled job and task process.

Change is in the air

Petri_162x87If you have read my blog for any length of time, or followed me, then you know that I have contributed a lot of content to a number of online resources over the years, often on a recurring basis. You may not realize it, but spreading out my workload over several sites can be quite demanding. After a lot of deliberation, I’ve decided to consolidate all of my online writing efforts with the Petri IT Knowledgebase.

The Petri IT Knowledgebase has been around since 1999 and has always been a source of high quality content for IT Pros.  For the longest time it had a domain name. But now you can find it at I will be publishing all of my online content exclusively at Petri where I will be a contributing editor. The site is being re-launched, lots of exciting things are in the works and I’m looking forward to being a part of it. At Petri, I will be primarily responsible for PowerShell related content. But you can expect to see me write about Active Directory, Group Policy, WMI, Hyper-V and Windows Server 2012 (and later).

I will still be blogging here and I will continue to create courses at Pluralsight. You will still find me at conferences like TechEd (or whatever it gets renamed) and the PowerShell Summit. I’ll still be doing PowerShell-related consulting and training on my own as well. Naturally, all of my existing content “in the wild” will remain where it is.

In most regards, nothing really changes other than the fact that you only have one place to check for my latest work. I hope you’ll come along for a great ride.