I have a ton of Powershell code I’ve written over the last 6 years or so that I’m in the process of cleaning up and looking to share. I plan on re-presenting them as a set of scripts and script modules I’ll be featuring in a series of blog posts coming in the near future.
I’ll start simply. I have a new script module called bsti.conversion that has a single function: ConvertTo-TimeSpan
I always thought it was neat that you could type in 1kb and Powershell would convert that value to 1024. You can also use mb (megabytes), tb (terabytes), and pb (petabytes). I don’t see that eb (exabytes) works. In any case, I always wished I could do the same with time units like this:
12m (minutes) or 24h (hours) or 7d (days)
The ConvertTo-TimeSpan function I’ve included in this module does just that.
What I use this for is I have functions and scripts I like to write that require the user to pass in an easy time unit value.
This functionality can also be achieved by Timespan conversion like so:
[Timespan](“1.00:00:00”) # 1 day
[Timespan](“1.6:00:00”) # 1 day, 6 hours
[Timespan](“1:22:00”) # 1 hour, 22 minutes
The conversion function is a little less precise, but a bit more human-readable, which is important to me since most of my users are not .NET programmers and don’t understand the format of a timespan object right offhand.
The function in this module supports both formats:
The module files can be downloaded here.
Once downloaded, extract the folder to the C:\windows\system32\windowspowershell\v1.0\modules directory. The final structure should look like this:
Then just use the Import-Module bsti.conversion command as shown above.
Not bad for a start, hope you enjoy.
UPDATE: I’m adding my stuff to GitHub. Bear with me while I come up-to-speed on how to use it. Find this module project here: