Read original post by Hermit Dave at Invoke IT Blog
I found this code a while back and its been very handy at times. I have no idea where I found it so I apologise for not attributing it to the writer. Hope this is helpful to others as it has been to me.